See our books for programmers (Rails, React.js, blogging, remote)

Why Smalltalk instead of Ruby

Hello, it’s Andrzej Krzywda from Arkency here. Today we have a special guest post from Richard Eng, the man who is behind the Smalltalk Renaissance.

I’ve been fascinated with Smalltalk since my University. In a way, my Ruby code is Smalltalk-infected all the time. Many of the great things in programming come from Smalltalk, like MVC, IDE, refactoring.

Smalltalk has its history, but it’s also still in use in huge, production systems. As Ruby developers we often look at the new, shiny languages. Maybe we can also look at something less new? Maybe we can get inspired with Smalltalk?

I’ll leave you with Richard and his strong arguments for Smalltalk, enjoy! :)

continue reading →

Safer Rails database migrations with Soundcloud's Large Hadron Migrator

When I first started using Rails years ago I fell in love with the concept of database migrations. Perhaps because at the time I was working on commercial projects in C# which lacked this and I could feel the difference. The fact that for many years the concept remained almost the same with some minor improvements speaks for itself. Ruby on Rails continues evolving all the time but migrations remain simple.

However, there is an elephant in the room.

continue reading →

Patterns for dealing with uncertainty

In programming we are often dealing with an uncertainity. We don’t know, we are not sure if something happened or not. Or we are not sure about the result. Especially when it comes to networking/distributed systems but also in other contexts. What I find interesting is that in many cases the techniques used to handle such problems are very similar.

continue reading →

Recovering unbootable NixOS instance using Hetzner rescue mode

Some time ago we had a small fuckup with one of our CI build machines. One of the devs was changing sizes of the file system partitions and he forgot to commit new NixOS configuration to the git repository where we synchronize it. After some time, I’ve uploaded NixOS config from git repo (which had, like I said, outdated configuration) to the machine and run nixos-rebuild --switch which essentialy made system into unbootable state because of wrong UUIDs in /etc/fstab.

continue reading →

Testable Javascript with pure functions

What if I told you that covering javascript code with tests can be easy and pleasant experience?

There’s one simple rule you need to follow in order to achieve that: keep your functions pure or in other words keep your code side-effect free. And all of a sudden you don’t need to mock anything, or emulate browser, or do any other not logic related stuff.

continue reading →

Developers as DDD bounded contexts representatives

Recently, I’ve been preparing to my webinar about introducing DDD to existing projects/teams.

One DDD part which is not always easy to explain is actually the main strategic pattern - bounded contexts. For the webinar purpose I came up with the idea of showing that in our programming teams we also have bounded contexts. What’s better, most of us, represent different bounded contexts.

In this blogpost I’d like to highlight some of such contexts.

continue reading →

Hourly Billing is Nuts

When it comes to my salary, I am an ordinary guy who earns $ X per hour. I’ve been working this way since I joined Arkency, and I never thought much about it. I’ve been happy that if I need vacations or break, I can just take them (properly communicating it with the clients, of course) without much hassle. When I feel great, and I am inspired to work and work and work, I can just log more hours without thinking much about it as well. Just like monthly salary, hourly salary is a safe way to live. But is it the most rewarding way to live?

Hourly Billing is Nuts challenged my perception that hourly billing is the best way possible. I started to notice the bad parts as well, not only the good ones. I don’t agree completely with some parts of the book, but it got me thinking.

continue reading →

Minimal decoupled subsystems in your rails app

There are multiple ways to implement communication between two separate microservices in your application. Messaging is often the most recommended way of doing this. However, you probably heard that “You must be this tall to use microservices”. In other words, your project must be certain size and your organization must be mature (in terms of DevOps, monitoring, etc.) to split your app into separately running and deployed processes. But that doesn’t mean you can’t benefit from decoupling individual subsystems in your application earlier.

continue reading →

Phases of refactoring complex Rails apps

Refactoring is a on-going process that is necessary in big Rails applications. Without it, you can quickly get into trouble - not only your code quality will suffer, but pieces of your architecture - models, controllers and views will get more and more coupled together. This is not a nice separation you had at the beginning of the project - it can quickly transform into an entangled mess of callbacks, going by relationships through half of the system to do stuff, and horrible things like that.

continue reading →

The quotes from the Post Rails Book Bundle books

Given that I now looked at all the Post Rails Book Bundle (Psst, the offer ends on Friday!) books, I’ve decided to pick some quotes which may shed more light into the whole message. This may help you understand the different points of views reflected by each author. Some of the authors are very opinionated and use a strong language, whiles others seem to quite positive towards Rails, but show their ways of extending The Rails Way.

What the books share is the view that The Rails Way may not be enough. They also share the constructive approach - they all present some alternatives. However, the books differ in “what’s next”. Thanks to the bundle you can have a wide perspective on the possible alternatives.

continue reading →

Implementing & Testing SOAP API clients in Ruby

The bigger your application, the more likely you will need to integrate with less common APIs. This time, we are going to discuss testing communication with SOAP based services. It’s no big deal. Still better than gzipped XMLs over SFTP (I will leave that story to another time).

I am always a bit anxious when I hear SOAP API. It sounds so enterprisey and intimidating. But it doesn’t need to be. Also, I usually prematurely worry that Ruby tooling won’t be good enough to handle all those XMLs. Perhaps this is because of some of my memories of terrible SOAP APIs that I needed to integrate with when I was working as a .NET developer. But SOAP is not inherently evil. In fact, it has some good sides as well.

continue reading →

Always present association

Recently my colleague showed my a little trick that I found to be very useful in some situations. It’s nothing fancy or mind-blowing or unusual in terms of using Ruby. It’s just applied in a way that I haven’t seen before. It kind of even seems obvious after seeing it :)

continue reading →

Cover all test cases with #permutation

When dealing with system which cooperate with many other subsystems in an asynchronous way, you are presented with a challenge. Due to the nature of such systems, messages may not arrive always in the same order. How do you test that your code will react in the same way in all cases?

Let me present what I used to be doing and how I changed my approach. The example will be based on a saga but it applies to any solution that you want to test for order independence.

continue reading →

API of the future

The “Frontend-friendly Rails” book is now live!

Here is what Ryan Platte (one of the readers) wrote after reading the book:

I’m very experienced with Rails, and I’ve built production apps in React. But faced with starting a new Rails+React integration, I didn’t look forward to arguing with Sprockets or undoing other Rails “opinions”. Frontend Ready Rails pointed me to a clean setup with easy-to-follow steps to do it right the first time. And every step is explained thoroughly so I understand the reasoning behind each part of the advice.

With this book, I basically got an experienced pair to step through this setup with me. I recommend it to anyone who wants to integrate React into their Rails app the right way.

Click here to buy the book!

Use the FF_RAILS_BLOG coupon to get 40% off!

API is a constantly evolving topic. Today, the most of APIs we’re all using are REST, JSON-based APIs. That was not the case a few years ago, when XML was a king in terms of response formats and techniques like XML RPC was quite popular.

But is the current state of API is here to stay? Do REST-based APIs scale well? Do they provide an optimal experience for integrated clients?

I don’t know the answer to this question. What I know is that there are companies that are challenging this idea - and you can try out their solutions today. Maybe those solutions will be a better fit for your project?

continue reading →

Rails Refactoring Podcast #6 - Frontend Friendly Rails

In this episode of Rails Refactoring Podcast, Wiktor and Marcin are discussing new Frontend-Friendly Rails book. It tells about improving frontend infrastructure provided by Rails. We are covering few topics from the book:

  • UUID and Rails
  • Modern frontend infrastructure with Node.js
  • ESLint

Download MP3 file.

You can subscribe to Rails Refactoring Podcast on RSS or on iTunes.

Show notes

Mutation testing of Rails views

Thanks to mutation testing we can get much higher confidence while working with Ruby/Rails apps. There is one area, though, where I’ve been struggling to make mutant to work - the Rails views. People use erb or haml and they’re both not a proper Ruby code, they’re templating languages.

In this post, I’m showing a trick which can help make Rails views covered by mutation testing coverage.

continue reading →

Is Rails a good fit for writing rich frontend applications?

This is a question I’ve asked myself months ago, working as a consultant for a client with a quite unique app.

Does it make sense to stick with Rails? Maybe it’s a good time to drop it?

Ruby on Rails worked well in the app for quite a while. It was enterprise system for a rather interesting clients: They were accustomed to desktop-like experience of their tools. They were using classic spreadsheets software like Microsoft Excel back then. This was the first project I’ve worked on where the particular way of how user interface works was the real business requirement.

continue reading →

Use ES2015 with Rails today - what & how

This is a content which was previously published as a mailing campaign in the Arkency Newsletter. This promotes our new book - Frontend Friendly Rails which is available on sale now. Use FF_RAILS_BLOG to get 40% discount on the book, which you can buy here.

ECMAScript 2015 is the new standard of JavaScript, popularised mostly by communities around React.js view library. While Angular people chose TypeScript for their language of choice and Ember is (mostly) unopinionated about it, React people tend to use ES2015 extensively.

continue reading →

See how we create books. Live

We are in the middle of a process of converting our bestselling book Rails Meets React from CoffeeScript to ES6. This book turned out to be a huge help for many Rails developers seeking a sane way to create their front end applications.

Many people are not using CoffeeScript and could use the information from the book. This is our main request for improving this book, we got from you all. And we are providing this upgrade to all people, who will ever buy Rails Meets React

Working on a book on a live stream

The process of rewriting the content may be interesting for people wanting to convert their React codebase from CoffeeScript to ES6. So, I thought it may be a good time to experiment with video streaming.

continue reading →

One more step to DDD in a legacy rails app

Recently I picked up a ticket from support team of one of our clients. Few months ago VAT rates have changed in Norway - 5% became 10% and 12% became 15%. It has some implications to platform users — event organizers, since they can choose which VAT rate applies to products which they offer to the ticket buyers. You’ll learn why I haven’t just updated db column.

continue reading →

The anatomy of Domain Event

Almost 2 years and over 16 million domain events ago I’ve started a process of “switching the mindset”. I had no production experience with Event Sourcing (BTW it still is used only in some parts of the application, but that’s a topic for another post), I had only a limited experience with Domain Driven Design (mainly knowing the tactical patterns). During that time, a lot has changed.

continue reading →

Packaging ruby programs in NixOS

Recently at Arkency we’re exploring how NixOS could fit our infrastructure. From a few weeks we’ve switched most of our projects CI systems from CircleCI to Buildkite. Buildkite offers unique offer in which it is us who provide infrastructure and containers to test our applications so we’ve decided to setup these containers with NixOS and we are by far happy with this solution.

However in this post I would like to describe how to package a simple ruby program, based on simple password manager CLI utility - pws. I’ve chose such a simple program to reduce the scope of this post - I hope that in future I’ll be able to describe more complicated cases.

continue reading →

How I hunted the most odd ruby bug

Every now and then there comes a bug in programmer’s life that is different than anything else you’ve encountered so far. Last time for me it was 3 days of debugging to find out that MySQL was returning incorrect results. We didn’t have to do much to fix it. We removed an index and created it again from scratch. There, problem gone. But that was a few years ago.

Last week I was hunting an entirely different beast. But before we dive into details, let me tell you a bit about the business story behind it.

continue reading →

Custom type-casting with ActiveRecord, Virtus and dry-types

In Drop this before validation and just use a setter method I showed you how to avoid a common pattern of using before_validation to fix the data. Instead I proposed you just overwrite the setter, call your custom logic there and use super. I also showed you what you can do if you can’t easily call super .

But sometimes to properly transform the incoming data or attributes you just need to improve the type-casting logic. And that’s it. So let’s see how you can add your custom typecasting rules to a project.

And let’s continue with the simple example of stripped string.

continue reading →

2 years after the first event - The Saga Pattern

As you build more advanced solutions, you may find that certain interactions in your system depend on more than one bounded context. Order, Inventory, Payments, Delivery. To deliver one feature often many sub-system are involved. But you want the modules to be isolated and independent. Yet something must coordinate their work and business processes. Welcome the choreographer - the Saga Pattern a.k.a. Process Manager.

continue reading →

Creating new content types in Rails 4.2

While working on the application for React.js+Redux workshop I’ve decided to follow the JSON API specification of responses for my API endpoints. Apart from a fact that following the spec allowed me to avoid bikeshedding, there was also an interesting issue I needed to solve with Rails.

In JSON API specification there is a requirement about the Content-Type being set to an appropriate value. It’s great, because it allows generic clients to distinguish JSONAPI-compliant endpoints. Not to mention you can serve your old API while hitting the endpoint with an application/json Content-Type and have your new API responses crafted in an iterative way for the same endpoints.

While being a very good thing, there was a small problem I’ve needed to solve. First of all - how to inform Rails that you’ll be using the new Content-Type and make it possible to use respond_to in my controllers? And secondly - how to tell Rails that JSON API requests are very similar to JSON requests, thus request params must be a JSON parsed from the request’s body?

I’ve managed to solve both problems and I’m happy with this solution. In this article I’d like to show you how it can be done with Rails.

continue reading →

How and why should you use JSON API in your Rails API?

Crafting a well-behaving API is a virtue. It is not easy to come up with good standards of serializing resources, handling errors and providing HATEOAS utilities to your design. There are a lot application-level concerns you need to make - whether you want to send back responses in mutation requests (like PUT/PATCH/POST requests) or just use HTTP headers. And it is hard - and by hard I mean you need to spend some time to get it right.

There are other things you need to be focused on which are far more important than your API. Good understanding of your domain, choosing a right architecture of your whole app or implementing business rules in a testable and correct way - those are real challenges you need to solve in the first place.

JSON API is a great solution to not waste hours on reinventing the wheel in terms of your API responses design. It is a great, extensible response standard which can save your time - both on the backend side and the client side. Your clients can leverage you’re using an established standard to implement an integration with your API in a cleaner and faster way.

There is an easy way to use JSON API with using a great Active Model Serializers gem. In this article I’d like to show you how (and why!).

continue reading →

Private classes in Ruby

One of the most common way to make some part of your code more understandable and explicit is to extract a class. However, many times this class is not intended for public usage. It’s an implementation detail of a bigger unit. It should not be used be anyone else but the module in which it is defined.

So how do we hide such class so that others are not tempted to use it? So that it is clear that it is an implementation detail?

continue reading →

How to teach React.js properly? A quick preview of wroc_love.rb workshop agenda

Hey there! My name is Marcin and I’m a co-author of two Arkency books you propably already know - Rails meets React.js and React.js by Example. In this short blogpost I’d like to invite you to learn React.js with me - and this is quite a journey!

Long story short, Arkency fell in love in React.js. And when we fell in love in something, we’re always sharing this love with others. We made a lot resources about the topic. All because we want to teach you how to write React.js applications.

Workshop is a natural step further to achieve this goal. But how to teach React.js in a better way? How to take an advantage a stationary workshop gives to learn you in an optimal way? What can you expect from React.js workshops from Arkency?

continue reading →

Rails: MVP vs prototype

In the last blog post I explained my approach to using Rails to quickly start a new app. In short - I’m starting with Rails but I also learnt how to gradually escape from the framework and separate the frontend.

Janko Marohnic commented on that and I thought it would be nice to reply here, as the reply covers the distinction between an MVP and a prototype.

continue reading →

Where and why I'm still using Rails

I’ve had many interesting conversations with experienced Ruby/Rails programmers recently. One of the topics that often pops up is when it makes sense (for us) to still use Rails, given the variety of other choices. This blogpost aims to summarize some of the views here.

continue reading →

One event to rule them all

Today I was asked a question:

How to ensure that domain event published by one of the aggregates is available in another aggregate?

The story is simple. The user, who is a member of some organization, is registering a new fuckup (maybe by using Slack command). The fuckup is reported by just entering its title. It is reported in the context of the organization where the user belongs. The rest is not important here but what we want to achieve is: modify a state of an organization aggregate and, at the same time, create new fuckup aggregate.

continue reading →

Loading all data when starting Flux SPA

Recently we’ve been working on an application which is a typical SPA which uses the Flux approach.

After some time we had a problem that besides our frontend being SPA, each time we clicked on link leading to some “page”, we’re loading data again, even if this data was loaded before. We’ve decided that the simplest solution would be to load all data in the beginning and display an animation when it’s loading.

In the future when necessity to hit refresh each time we want fresh data would become troublesome we could simply add Pusher-like solution to update data in real-time.

In this post I want to present you solution how our implementation looked like. In our application we are using ES6 (using Babel) and alt.js as a library delivering Flux features.

continue reading →

Stable Circle CI builds with PhantomJS for larger Rails-backed frontend apps

The original photo is available on stocksnap. Author: Stephen Radford.

One of the projects we work on is a rather large frontend app, built with React and backed by Rails. The app has quite a few tests and obviously we want them to run as fast as possible. We have tried a few drivers along the way but eventually we have chosen PhantomJS. So far we are pretty much happy about the choice, but it wasn’t always like that. Especially when it comes to our CI server where the tests would quite often fail randomly and prevent the app from being deployed. The random failures have been the biggest pain so far and so here are a few tricks that have helped us keep the build green.

continue reading →

In-Memory Fake Adapters

There are two common techniques for specifying in a test the behavior of a 3rd party system:

  • stubbing of an adapter/gem methods.
  • stubbing the HTTP requests triggered by those adapters/gems.

I would like to present you a third option — In-Memory Fake Adapters and show an example of one.

continue reading →

Monitoring services and adapters in your Rails app with Honeybadger, NewRelic and #prepend

The bigger your app gets the higher chance that it will need to integrate with multiple of external services, providers and APIs. Sometimes they work, sometimes they don’t. Sometimes it doesn’t matter when they are down or behaving problematically. Sometimes it costs your clients money.

Like when a payment gateway is having problems on Black Friday.

Can you imagine?

But the first step to knowing about the problem and the urgency of a situation is to monitor it. So we will start with that.

continue reading →

Arkency React.js resources

It has been some time (almost 2 years?) since we started using React.js at Arkency. It quickly propagated to all of our projects. Along the way, we’ve been blogging a lot about what we learnt.

So far we’ve released:

  • 28 blogposts
  • 5 open repositories
  • React.js koans
  • 7 YT videos
  • 2 books (with repos)
  • dozens of emails to our React Kung Fu mailing list

This blogpost is an attempt to put all the resources in one place.

continue reading →

Slack-driven blogposts

Slack (or any other team communication tool) may be a good source for your blogposts.

You may have explained something to your team on the Slack channel. You already verbalised your thoughts in a written manner. That’s the biggest part of writing a blog post! Use it to your benefit now. Turn it into a blogpost.

continue reading →

Creating custom Heroku buildpack for Webpack and Ruby on Rails integration

Heroku and Rails loves each other from long time - and this combo is still widely used both by beginners and experts to build and host their web applications. It’s easy and it’s fast to host an app - and those two factors are very important in early stages of the project’s lifecycle.

In modern web applications backends and frontends are often equally sophisticated - and unfortunately solutions that Sprockets offers by default are suboptimal choice. Using ECMAScript 2015 features, modern modularization tools and keeping track of dependencies are hard to achieve in typical Rails asset pipeline. That’s why modern JavaScript tooling is used more and more often to deliver those features.

In Arkency we use Webpack and Babel.js to manage and compile code written in modern dialects of JavaScript. Apart from configuration and Rails integration problems there is also a problem of deployment and configuring the deploy machinery to wire everything together. In this article I’d like to show you how you can deploy Rails + Webpack combo to Heroku. This is the thing that is expected from us by our clients from time to time.

continue reading →

Do you have a framework for dealing with emergencies?

In my pre-Arkency life, I worked for a corp.

Keep in mind that it was my very beginning of the commercial-IT world. I sometimes felt lost inside this huge DevOps machine. Lost and alone - as usually, when something breaks, there was nobody to ask for help.

It had to happen. One day, by accident, I ran some kind of a DB-clean-up script, with the wrong date, on production. The script’s job was to delete records that are old enough. While fiddling with the script, I changed the definition of records old enough to records visible today (not closed). And accidentally ran the script.

continue reading →

CQRS example in the Rails app

Recently I have worked in a new project for some time. We implement an application where one functionality is to show an organization’s (tree-like) structure. The structure contains information about relations between employees. I have been thinking how to build this feature. I was wondering if I should go typical way implementing all CRUD actions. In this case I would have to generate the structure for each call. I thought It will be faster. It is a startup. So until the project is young performance is not a problem. Although after few syncs we decided to go an another way.

continue reading →

Testing race conditions in your Rails app

From time to time, there comes a requirement in your application where you have to guarantee that something can be done at most X number of times. For example, only 15 people can subscribe to a course, only limited number of people can buy this physical or virtual product, only 200 people can go to a concert, etc. How do you test that this limitation actually work? And not only work but that it works under heavy load, when there are multiple customers trying to buy the last item because it is a hot event or the product is offered with a big discount?

continue reading →

How can Rails developers benefit from reading the Arkency books?

As a Ruby/Rails developer, you have so many books to learn from. The choice is sometimes too big which can lead to choice paralysis.

In this blogpost I’d like to focus on the different aspects of your developer life. There are so many skills to improve. The Rails skills are the obvious ones. But there’s much more than that. Working in a team, safe refactoring, well-structured frontend applications, communicating with other people, even blogging.

I’d like to explain how we’re helping with improving those skills with our Arkency books.

continue reading →

Three most telling files in legacy Rails apps

Photo available thanks to the courtesy of wackybadger. License: CC-BY-SA 2.0

When working in a consultancy agency the ability to work with legacy applications is necessary. Your clients very often come with their codebases. If the app is already in use a rewrite doesn’t sound like a good idea - it’s best to approach to make improvements incrementally.

But the truth is that this skill is very important for every Rails developer. Even if you’re working on your own projects or creating the Rails-based startup from scratch after some time your code will grow. Tests are very likely to become slower. There will be more and more implicitness within your code. You accept that because you are within the context for a long time. You know tradeoffs, assumptions and decisions - often you made them by yourself. It’s good to have skills to measure the situation and have some kind of guidelines to protect yourself from mistakes while refactoring.

In this blog post, I want to show you three simple techniques we use to get ourselves a solid starting point for working with legacy Rails apps. You will be able to apply it to projects you’re working on and improve your planning and refactoring thanks to it.

continue reading →

Null Object pattern in practice

Wikipedia describes Null Object as an object with defined neutral behavior.

Martin Fowler says Instead of returning null, or some odd value, return a Special Case that has the same interface as what the caller expects.

But null object pattern can also be seen as a way to simplify some parts of your code by reducing if-statements and introducing interface that is identical in both situations, when something is missing and when something is present.

continue reading →

Am I ignored in my async team?

When we work in async teams, we have many benefits from it - people not blocked on each other, freedom of place, freedom of time. We also have some drawbacks. You can’t expect an instant reply to whatever you ask for. In the nature of async, you can’t even be sure when you get the reply. What’s interesting, you can’t even be sure that all (any?) people actually received your message.

continue reading →

Arkency goes React

From its beginnings in 2007, Arkency was connected to Ruby and Rails. We’re still most active in those technologies. However, over time there’s another R-named technology that quickly won our hearts - React.js.

continue reading →

Thanks to repositories...

Source: Wikimedia Commons

I am working in Arkency for 2+ months now and building a tender documentation system for our client. The app is interesting because it has a dynamic data structure constructed by its users. I would like to tell you about my approaches to the system implementation and why the repository pattern allows me to be more safe while data structure changes.

continue reading →

How good are your Ruby tests? Testing your tests with mutant

New-feature-bugs vs regression-bugs

There are many kinds of bugs. For the sake of simplicity let me divide them into new-feature-bugs and regression-bugs.

New-feature-bugs are the ones that show up when you just introduce a totally new feature.

Let’s say you’re working on yet another social network app. You’re adding the “friendship” feature. For some reason, your implementation allows inviting a person, even though the invitee was already banned. You’re showing this to the customer and they catch the bug on the testing server. They’re not happy that you missed this case. However, it’s something that can be forgiven, as it was caught quickly and wasn’t causing any damage.

continue reading →

You can use CoffeeScript classes with React - pros and cons

One of the big advantages of React components is that they are easy to write. You create an object literal and provide functions as fields of your object. They you pass this object to a React.createClass function.

In the past React.createClass was a smart piece of code. It was responsible for creating a component’s constructor and instantiating all fields necessary to make your plain object renderable using React.renderComponent. It was not an idiomatic JavaScript at all. Not to mention it broke the basic SRP principles.

It changed with a 0.12 version of React. React developers took a lot of effort to improve this situation. A new terminology was introduced. React.createClass now does a lot less.

One of the most important change for me is that now you can use CoffeeScript classes to create React components. Apart from the nicer syntax, it makes your code more idiomatic. It emphasizes the fact that your components are not a ‘magic’ React thing, but just CoffeeScript objects. I want to show you how you can use the new syntax - and what are pros and cons of this new approach.

continue reading →

Start using ES6 with Rails today

Source: Asif Salman

The thing that made me fond of writing front-end code was CoffeeScript. It didn’t drastically change syntax. Coffee introduced many features that made my life as a web developer much easier (e.g. destruction and existential operators). That was a real game changer for Rails developers. We can write our front-end in language that is similar to Ruby and defends us from quirks of JavaScript.

continue reading →

Using domain events as success/failure messages

When you publish an event on success make sure you publish on failure too

We had an issue recently with one of our internal gems used to handle all communication with a external payment gateway. We are using gems to abstract a bounded context (payments here) and to have an abstract anti-corruption layer on top of external system’s API.

continue reading →

Building a React.js event log in a Rails admin panel

Recently I talked with some awesome Rails developers about the Event Sourcing. We talked about introducing ES concept in a legacy Rails applications. That conversation inspired me to write a post about our experiences with the Event Sourcing. The most important thing to remember is that we don’t have to implement all blocks related to ES at the beginning (Aggregates, Read models, Denormalizers and so on). You can implement only one pattern and improve it slowly to full an Event Sourcing implementation. This strategy will involve small steps down a long road. This is how we work in the Arkency.

continue reading →

One year of React.js in Arkency

What always makes me happy with new technologies are hidden positive side-effects I’ve never expected to happen. When I first introduced React in Arkency, which was on 4th of March 2014 I never expected it’ll become so popular in our team. But should I be surprised? Let me tell you a story of how React allowed us to re-think our frontend architecture and make us a lot more productive.

continue reading →

How to store emoji in a Rails app with a MySQL database

Suppose you have a Rails app and you are storing your data in a MySQL database. You were requested to add emoji support to your application. Probably you are thinking:

Oh, that’s simple, it’s just unicode, isn’t it?

The answer is: no. Unfortunately, MySQL’s utf8 character set allows to store only a subset of Unicode characters - only those characters that consist of one to three bytes. Inserting characters that require 4 bytes would result in corrupted data in your database.

continue reading →

Extract a service object using SimpleDelegator

It’s now more than 1 year since I released the first beta release (the final release was ready in December 2014) of the “Fearless Refactoring: Rails controllers” book. Many of the readers were pointing to the one technique which was especially useful to them - extracting a service object using SimpleDelegator.

This technique has also been very popular in our Arkency team. It gives you a nice way of extracting a service object immediately, within minutes. It is based on a bit of a hack, though. The idea is to treat this hack as a temporary solution to make the transition to the service object more easy.

continue reading →

On my radar: RethinkDB + React.js + Rails

Sometimes you hear positive things about a technology and you put it on your radar. To explore it when you have some time. To get a feeling if it is fun at all. To mix and match things together to see what comes out of it.

For me recently it was RethinkDB . Its slogan says The open-source database for the realtime web. Interesting enough to get me curious. RethinkDB pushes JSON to your apps in realtime also sounded good.

I was sick one week ago so I had a moment to give it a try.

continue reading →

Why I want to introduce mutation testing to the rails_event_store gem

We have recently released the RailsEventStore project. Its goal is to make it easier for Rails developers to introduce events into their applications.

During the development we try to do TDD and have a good test coverage. The traditional test coverage tools have some limitations, though. Mutation testing is a different approach. In this post I’d like to highlight why using mutation testing may be a good choice.

continue reading →

Beautiful confirm window with React

When designing your web application, you would like the user to confirm some actions sometimes. For example, you may want the user to confirm deletion of his data. There is window.confirm JavaScript method that might be useful in this case but it could not be styled and just displays native browser’s dialog window. In this article I would like to show you how to create React component as a replacement for window.confirm that can have similar behaviour and your application’s look & feel. It has similar API to window.confirm so migration should be really easy.

continue reading →

Rails meets React.js is out: What you can find inside?

Dealing with frontends can be a tedious task for Rails developers. In Arkency, we blogged the about frontend development a lot, searching for the best solutions and practices. React.js is one of the most successful findings for us. It brought solid solution to a problem of building modern, dynamic interfaces to web applications we were working on. React.js is one of jewels in our toolbox now.

There is a common practice in our company to propagate knowledge within and outside of the team with blogposts and books. After a few months of work, we’re happy to present you a book with our knowledge about React.js.

We had a great fun writing it. We filled it with our best practices, theory behind React and tons of examples. You can buy it right now - with all future updates for free.

Interested? Let me tell you more about what you can find inside.

continue reading →

Gulp - a modern approach to asset pipeline for Rails developers

Rails asset pipeline is one of things that makes Rails great for creating simple applications fast. It solves a big problem of serving our assets efficiently in both development and production environment.

While being very useful, Sprockets has its age. There is a rapid growth of technologies around JavaScript. A growth which often cannot be used in an easy way by Rails developers. There are good technologies for code modularization, languages transpiled to JS, CSS preprocessors and much, much more. Those technologies are easy to use in Node.js-based stacks, but not in Rails.

Rails asset pipeline has a big advantage of being painless to use. We do not need to configure anything to have our assets served or precompiled. There is a built-in file require system to help us split our code into files. In bigger frontend codebases we’d live happier with more sophisticated solutions - and we cannot throw away a legacy that Sprockets have. How to live with both CommonJS and Sprockets require system? How to optimize our compilation steps? Sprockets is implicitly doing its job - and that’s great until you want to have something more.

Fortunately, asset serving is a low-hanging fruit when it comes to decoupling parts from Rails. You can easily remove all asset serving responsibilities from Rails and use a modern build system like Gulp to compile your assets.

In this blogpost I’d like to show you how to replicate major part of Sprockets responsibilities in 82 lines of JavaScript code, with ability to use CommonJS and modern technologies straight from npm. As a bonus this 82 lines will also generate source maps for your CoffeeScript and Sass.

continue reading →

Stream pagination in Greg's Event Store

Every stream in Event Store is represented as a paged feed. This is because reading from streams based on an AtomPub protocol. A paged feed is a set of feed documents where each document contains some part of a whole data. This is very useful solution when the number of information is very large. So basically in the ES reading a stream is a process of collecting events in small portions. You can find some information about this feature in main Event Store’s documentation but in my opinion It is described very briefly. So this is why I decided to write this blog post.

continue reading →

Tracking down unused templates

Few days ago, my colleague raised #sci-fi idea. Maybe we could somehow track templates rendered in application to track down which ones aren’t used? Maybe we could have metrics how often they’re used? Metrics? That sounds like gathering data using We have already installed Chillout gem in other project I work at.

continue reading →

Explaining Greg's Event Store

Event Store is a domain specific database for people who use the Event Sourcing pattern in their apps. It is a functional database which based on a publish-subscribe messages pattern. Why functional? It uses a functional language as its query language. In ES It is the Javascript. I will say something more about this later. The lead architect and designer of Event Store is Greg Young who provides commercial support for the database. I decided to create this two-part tutorial to bring the idea closer to you. I will describe issues related to Event Store in the first part and I will present some simple examples of the ES usage in the second one.

continue reading →

Why use Event Sourcing

Event Sourcing relies on not storing current state. All of application state is first level derivative out of facts. That opens completely new ways of architecting our applications.

But why?

There is a lot of reasons to use Event Sourcing. When you browse through Greg Young’s and other articles & talks you will find most of them. Usually they mention:

  • It is not a new concept, a lot of domains in real world works like that. Check out your bank statement. It’s not the current state - it is log of domain events. Or if you are not still convinced talk to your accountant ;)
  • By replaying an event we could get a state of an object (or let’s use correct term here: aggregate) for any moment in time. That could greatly help us to understand our domain, why things changed and debug really nasty errors.
  • There is no coupling between the representation of current state in the domain and in storage.
  • Append-only model storing events is a far easier model to scale. And by having a read model we could have best of both worlds. Read side optimised for fast queries and write side highly optimised for writes (and since there is no delete here, it could really be fast writes).
  • Beside the “hard” data we also store user’s intentions. The order of events stored could be used to analyse what user was really doing.
  • We are avoiding impedance mismatch between object oriented and relational world.
  • Audit log for free. And this time the audit log really has all the changes (remember there is no change of state if there is an event for that).
continue reading →

Fast introduction to Event Sourcing for Ruby programmers

Many applications store a current state in these days. Although there are situations where we want to see something more than a current information about our domain model. If you feel that need Event Sourcing will help you here.

The Event Sourcing is an architectural pattern which allows us to keep information about object’s state as a collection of events. These events represent modifications of our model. If we want to recreate current state we have to apply events on our „clean” object.

continue reading →

Configurable dependencies in Angular.js

Photo available thanks to the courtesy of streetmatt. CC BY 2.0

Angular.js is often a technology of choice when it comes to creating dynamic frontends for Rails applications. As every framework, Angular has it’s flaws - but one of the most interesting features it has is built-in powerful dependency injection mechanism. Compared to Rails, it is a great advantage - to achieve similar results you would need to use external gems like dependor. Here you have this mechanism out of the box.

In my recent work I needed to learn Angular from scratch. After learning about providers mechanism, my first question was: Can I have a dependency and configure which implementation I can choose? Apparently, with a little knowledge about JavaScript and Angular it was possible to come with a very elegant solution of this problem.

continue reading →

You don't need to wait for your backend: Decisions and Consequences

Photo remix available thanks to the courtesy of mripp. CC BY 2.0

As front-end developer your part is often to provide the best possible experience for your application’s end-users. In standard Rails application everything is rather easy - user clicks on the submit button and waits for an update. User then sees fully updated data. Due to async nature of dynamic front-ends it is often missed what happens in the ‘mid-time’ of your user’s transaction - button is clicked and user waits for some kind of notification that his task is completed. What should be displayed? What if a failure occurs? There are at least two decisions you can take to answer those questions.

continue reading →

Use your gettext translations in your React components

Photo remix available thanks to the courtesy of miguelb. CC BY 2.0

In one of our projects, we are using gettext for i18n. We were putting Handlebars x-handlebars-template templates directly in Haml templates to provide translated views for frontend part - all translations were made on backend. Recently we have rewritten our frontend to React and decided not to use ruby for translations anymore.

continue reading →

How to split routes.rb into smaller parts?

Each application created using Ruby on Rails framework has a routing engine and config/routes.rb file where we define routes paths. That file very often becomes very large in the proces of development. Each additional line makes the routing file harder to maintain. Also, searching for specific paths during the development phase becomes increasingly difficult. Currently, I work on an application in which the routing file contains about 500LOC. Quite a lot, isn’t it? The solution is very simple. All you need to do is split the file into a couple of smaller ones.

continue reading →

The Beginners Guide to jQuery.Deferred and Promises for Ruby programmers

Working with asynchronous code is the bread and butter for frontend developers. You can find it hard when working with it at first - as a Rails developer, you live with code which is usually synchronous. Luckily, promises were something which allowed us to get a huge step forward to deal with callbacks in a sane way. While widely adopted by backend JavaScript developers, Promises and their tooling is something often missed by Rails devs.

It can be different - and you have all important libraries bundled by default in our Rails app. Let’s see what jQuery can offer you here - and I’ll discuss how I managed to solve typical async problem with features that jQuery provides.

continue reading →

Ruby Exceptions Equality

Few days ago my colleague was stuck for a moment when testing one service object. The service object was responsible for a batch operation. Basically operating on multiple objects and collecting the status of the action. Either it was successful or failed with an exception. We couldn’t get our equality assertion to work even though at first glance everything looked ok. We had to dig deeper.

continue reading →

It's easy to miss a higher level concept in an app

Just yesterday, I finished reading Understanding the Four Rules of Simple Design written by Corey Haines. I definitely enjoyed reading it. The examples are small, understandable and a good starting point for the small refactorings that follow. It’s a short, inexpensive book, but dense with compressed knowledge, and I can only recommend buying it. You can read it in a few hours, and contemplate it for much longer.

One of the examples inspired me to write this blogpost about higher level concepts. What does that even mean? Especially in terms of programming?

continue reading →

The categories of validations

There are many reasons why rails changed the landscape of web development when it was released. I think one of the aspects was how easy it was to communicate mistakes (errors) to the user. Validations is a very nice convention for CRUD applications. Over time however, many of our active record objects tend to grow in terms of validations. I think they fit at least into a few categories (probably more).

continue reading →

Don't forget about eager_load when extending autoload paths

I am sure you know about config.autoload_paths. A setting which allows you to add aditional directories (besides app/* which works out of box) that can be used for placing your .rb files. The documentation mentions a config.autoload_paths += %W(#{config.root}/extras) example. But the most common way to use it is probably to add lib directory (especially after the transition from rails 2 to rails 3).

Another (maybe not that common) usecase is to have some components (such as notification_center for example) in top-level directory. To make it possible for them to work with your app people are usually using:

config.autoload_paths += %W( #{config.root}/notification_center )


config.autoload_paths += %W( #{config.root}/notification_center/lib )

And it is all cool except for one thing they might have forgotten to mention to you. How it all works in production and what you can do to make it work better.

continue reading →

Frontend performance tips for web developers

Optimization has always been a tough topic. Donald Knuth said that premature optimization is the root of all evil. Performance is something that always causes emotions in web community. When we need it, we tune up our applications, try different and new servers, use load balancers, speed up our applications by playing with threads and processes, but sometimes we forget about frontend at all. Server side is important too, how if we need to provide fast-responding websites, we have to optimize them in our browsers as well. In this article I’d like to focus on client side and how to efficiently deliver content to end user.

continue reading →

How to start using Arrays in Rails with PostgreSQL

So far we covered a lot of PostgreSQL goodness. We’ve already talked about using uuid or storing hashes in our Rails applications with PostgreSQL database. Now is the time to do something in the middle of these topics (more complex than uuid, but easier than hstore) - we want to store list of simple values under one attribute. How can we do that? You may think “arrays” right now and you are correct. Let’s see how we can achieve that.

continue reading →

React.js and Dynamic Children - Why the Keys are Important

Recently I’ve been building a pretty dynamic interface based on google analytics data for one of our customers. There was a bug that I couldn’t quite figure out because of my wrong understanding of how react works. In the end it turned out to be a very easy fix and very important lesson on understanding react.js.

It is even pretty accurately described in react documentation however without showing what will go wrong and what kind of bugs you can expect if you don’t adhere to it. In other words, the documentation explains the right way but without going much into details about why.

continue reading →

Adapters 101

Sometimes people get confused as to what is the roles of adapters, how to use them, how to test them and how to configure them. Misunderstanging often comes from lack of examples so let’s see some of them.

continue reading →

Concurrency patterns in RubyMotion

The more we dive into RubyMotion, the more advanced topics we face with. Currently, in one of our RubyMotion applications we are implementing QR code scanning feature. Although it may seem already as a good topic for blogpost, this time we will focus on concurrency patterns in RubyMotion, because they are a good start for any advanced features in iOS like this 2D code recognition.

continue reading →

Burnout - do you need to change your job?

I’ve been reading recently a story on Hacker News about a programmer who (depending on who you ask for a diagnose in the thread) was suffering from burnout. Some commenters even suggested depression. There were many advices recommended (unfortunatelly I can’t find a link to the discussion right now) but one certainly spot my attention.

continue reading →

Truncating UTF8 Input For Apple Push Notifications (APNS) in Ruby

When sending push notifications (APNS) to apple devices such iPhone or iPad there is a constraint that makes implementing it a bit challenging:

The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit

This wouldn’t be a problem itself unless you want to put user input into the notification. This also wouldn’t be that hard unless the input can be international and contain non-ascii character. Which still would not be so hard, but the payload is in JSON and things get a little more complicated sometimes. Who said that formatting push notification is easy?

continue reading →

SSH authentication in 4 flavors

We are connecting with remote servers every day. Sometimes we explicitly provide passwords, sometimes it just happens without it. A lot of developers don’t care how it works internally, they just get access, so why to bother at all. There are a couple ways of authentication, which are worth to know and I’d like to present you them briefly.

continue reading →

Using ruby Range with custom classes

I am a huge fan of Ruby classes, their API and overall design. It’s still sometimes that something surprises me a little bit. I raise my eyebrow and need to find answers. What surprised me this time was Range class. But let’s start from the beginning (even though it is a long digression from the main topic).

continue reading →

Hidden features of Ruby you may not know about

How well do you know the language you’re using? What if I tell you that even you use it the whole day and every day it still can hide some tricks that you might not be aware of? I’d like to reveal some less or more known, but certainly interesting parts of Ruby to make you sure that you don’t miss anything.

continue reading →

6 front-end techniques for Rails developers. Part I: From big ball of mud to separated concerns

Photo remix available thanks to the courtesy of Clever Cupcakes. CC BY 2.0

Current trends in web development forces us to write more and more front-end code in our applications. Single Page Applications, content changes without refreshing, rich user experience using custom controls - all those requirements needs you to write code. And this code, as any other code, can quickly turn into a big ball of mud. It can happen when you lack proper tools in your toolbox to design it correctly.

In this course I want to share with you techniques and tools we’re using in our day-to-day work. Some of those allow you to create easier, more testable code. Some of those allow you to develop it faster, without losing quality. I believe it’s really worth to try these techniques and choose which suits you most.

In the part one, I want to present you a simple case of refactoring of a badly written front-end code to a stand-alone micro-app with proper encapsulation.

continue reading →

Why we use React.js in our Rails projects

Source: Subramanya Prasad

Programming interactive user interfaces using JavaScript might be a tough task. User calls some action and we need to update his view - manipulating DOM using tool like jQuery. It just doesn’t feel good enough to modify document’s elements by hand. It is also really hard to re-use already written parts of UI and compose them with each other.

Imagine if there was one tool, that would solve all these problems and help you deliver your front-end much faster. What if you didn’t have to worry about this whole DOM stuff when you just want to update the view?

How would you feel being as efficient as when developing your Rails backend, when it comes to user interface?

Here comes React.js!

continue reading →

4 ways to early return from a rails controller

When refactoring rails controllers you can stumble upon one gottcha. It’s hard to easily extract code into methods when it escapes flow from the controller method (usually after redirecting and sometimes after rendering). Here is an example:

1. redirect_to and return (classic)

class Controller
  def show
    unless @order.awaiting_payment? || @order.failed?
      redirect_to edit_order_path(@order) and return

    if invalid_order?
      redirect_to tickets_path(@order) and return

    # even more code over there ...

So that was our first classic redirect_to and return way.

Let’s not think for a moment what we are going to do later with this code, whether some of it should landed in models or services. Let’s just tackle the problem of extracting it into a controller method.

continue reading →

Code style matters

Have you ever wondered how your code looks? Exactly - no what it does or even how it is organized, but actually how it looks. One may think here “oh screw it”, but I want to present that it can matter and show you my various thoughts about that topic.

continue reading →

Developer matters

Have you ever wondered what does your regular workday look like? Do you have the same daily habits? So how is it going? Breakfast, coffee, daily standup, reading mails, some work, off-topic talk with coworkers, dinner, some work and the day is over? If you follow these chain (not necessary in the same order) it is important signal that things must change. Not tomorrow, but right now.

continue reading →

Microservices - 72 resources

Microservices - everyone talks about them nowadays. There’s no common understanding however what they are. I’ve been researching this topic for a while, gathering and evaluating articles, presentations and conference videos.

continue reading →

Service objects as a way of testing Rails apps (without factory_girl)

There’s been recently an interesting discussion about setting up the initial state of your tests. Some are in favor of using built-in Rails fixtures (because of speed and simplicity). Others are in favor of using factory_girl or similar gems. I can’t provide definite numbers but judging based on the apps that we review, in terms of adoption, factory_girl seems to have won.

I would like to present you a third alternative “Setting up tests with services” (the same ones you use in your production code, not ones crafted specifically for tests) and compare it to factory_girl to show where it might be beneficial to go with such approach.

continue reading →

From Rails to RubyMotion: basic toolkit

Have you noticed the tendency that development is moving strongly towards mobile? There are more and more projects with mobile companion, there are a lot of just-mobile software houses, and there are even only-mobile projects. What if a company has only web developers specialized in Ruby, but want to be really full-stack? Doesn’t matter, with Ruby, it can still goes mobile!

continue reading →

Real-time Web Apps

From the very beginning web pages were just static. Internet browsers received some HTML code to render and displayed it to user. When someone wanted to check if there are any news on our page, he had to refresh it and then some new data might appeared. Time to change it.

continue reading →

Effective async communication

What we mean by working asynchronously is not to always work async, to avoid meetings and video calls at all cost. But to rather prefer async way of communicating when it is favorable, when you are sure that sync discussion wouldn’t bring you much more. At first you might think that it is almost never but if you keep pushing yourself a little bit you will soon start to realize that you are getting better at it. In fact now we have much more async discussions than sync discussions.

continue reading →

Async & remote - toolbox

I’ve been speaking recently at a local IT entrepreneur meetup about remote work and about the ways a company can transition towards being more remote.

The part of the talk that seemed to be most interesting was the toolset that we’re using at the moment. I thought I’d share this list here, as well.

Remember, that tools should just support your process and not replace it. If your goals are clear to you and your team, then the tools are just implementation details.

continue reading →

Mastering Rails Validations: Contexts

Many times Rails programmers ask How can I skip one (or more) validations in Rails. The common usecase for it is that users with higher permissions are granted less strict validation rules. After all, what’s the point of being admin if admin cannot do more than normal user, right? With great power comes great responsibility and all of that yada yada yada. But back to the topic. Let’s start with something simple and refactor it a little bit to show Rails feature that I rerly see in use in the real world.

continue reading →

The biggest obstacle to start with Continuous Deployment - database migrations

Photo remix available thanks to the courtesy of Mark Engelbrecht. CC BY 2.0

There are still companies which disable the website during deploys with database migrations and believe that db migrations prevent them from going fully with CD. They even have time window for triggering such activities (usually early in the morning or late at night).

If you are working in a place like that, and you would deeply want in your heart to adopt Continuous Deployment but you can’t find a way to convince your boss, this is a step by step guide for you. Instead of going from zero to warp nine, you can go towards your goal with small steps that can be part of your current, normal tasks that you are doing for the client.

continue reading →

Zero uptime deploy

Photo remix available thanks to the courtesy of Rob Boudon. CC BY 2.0

Unicorn has a nice feature that bought it a lot of popularity and set standards for other Ruby web servers: The ability to do Zero Downtime Deploy, also known by the name rolling deploy or rolling restart aka hot restart. You start it by issuing USR2 signal. But here is something that most websites won’t tell you. It can fail and you won’t even notice. You will be thinking that everything went ok, living in Wonderland, whereas in reality your deploy achieved uptime of exactly 0 seconds.

So what you need is a small verification procedure that everything worked as expected. This article will demonstrate simple solution for achieving it in case you are using capistrano for deploying the app. However you can use very similar procedure if you deploy your app with other tools.

continue reading →

Don't call controller from background job, please. Do it differently!

Photo remix available thanks to the courtesy of francescomucio. CC BY 2.0

Some time ago while doing Code Review for one of our clients I stumbled on a very unexpected piece of code. Background job calling a controller.

class OrderPdfJob
  def self.perform(order_id, locale)
    controller =
    pdf = controller.generate_pdf_for_order(order_id, locale)
    OrderPdf.create file: pdf, order: order
    # ...

class PdfController < ApplicationController
  skip_before_filter :authenticate_user!

  def generate_pdf_for_order(order_id, locale)
    # ...

I was a bit speechless. Calling controller out of HTTP request/response loop sounds like an odd thing to do. I had to investigate and refactor.

continue reading →

2 ways to deal with big and complicated features

Photo remix available thanks to the courtesy of EladeManu. CC BY 2.0

From feature vision to stories

One of the challenges of managing software projects is delivering big features. We already told you that we prefer to work with small, prioritized and unassigned stories that anyone can take and finish. But how do any up there? Especially, if what the customer comes to you with, is a big document, describing the features that you must implement.

continue reading →

Sitemaps with a bit of Metal

Photo remix available thanks to the courtesy of tinkerbrad. CC BY 2.0

Sooner or later, you will probably start taking care about your application’s SEO, especially if it provides a lot of content and you want to be discovered by users in search engines results. There are several ways to do this in your Ruby app. You can create sitemap.xml file manually if there aren’t very much urls, but it will become pretty ineffective when you have more than a dozen or so. There are some very neat tools which will do this for you out of the box, even if you need a lot of customization.

continue reading →

Pretty, short urls for every route in your Rails app

Photo remix available thanks to the courtesy of Moyan Brenn. CC BY 2.0

One of our recent project had the requirement so that admins are able to generate short top level urls (like /cool) for every page in our system. Basically a url shortening service inside our app. This might be especially usefull in your app if those urls are meant to appear in printed materials (like /productName or /awesomePromotion). Let’s see what choices we have in our Rails routing.

continue reading →

37 signals was not lying, you win by being remote

There is such moment in developer’s life when you start looking for a new job, sooner or later. You can observe that even in Poland, there are plenty of Ruby on Rails job offers, often in very perspective companies. I probably could find interesting job in Poznań, where I live, but there were some presumptions which pushed me to apply to Arkency.

continue reading →

Rails and SOA: Do I really need to have this big app?

Developing complex web applications (not particularly Rails apps) is a tricky task. You write your models, controllers, services and optimize application architecture iteratively. But even with the great architecture when your application starts to be huge, bad things happen. Every little feature you’ll add will cost you precious time - tests must pass on your CI and workers needs to be reloaded every time you deploy. In addition, you begin to realize that mental overhead with keeping modules separated is huge - you have to remember a lot of things to keep it in right fashion. Ultimately, working on a project is hard, TDD technique is inefficient to use and you’re not happy at all with your code.

Have something gone wrong? No. You just didn’t notice that you need more applications than just one.

continue reading →

CoffeeScript acceptance tests

You’ve already learned how to implement simple model and view tests, so as I promised now I’ll show you how you can introduce acceptance tests on client-side. We’re not too far from this goal - you know how to write test cases, make assertions and “click through DOM”. Let’s apply some abstraction then - to look at our app like the end user.

continue reading →

3 ways to do eager loading (preloading) in Rails 3 & 4

You are probably already familiar with the method #includes for eager loading data from database if you are using Rails and ActiveRecord. But do you know why you someties get few small and nice SQL queries and sometimes one giant query with every table and column renamed? And do you know about #preload and #eager_load which can help you achieve the same goal? Are you aware of what changed in Rails 4 in that matter? If not, sit down and listen. This lesson won’t take long and will help you clarify some aspects of eager loading that you might not be yet familiar with.

continue reading →

Developers oriented project management: Leave tasks unassigned

As with software, improving your company is an ongoing process consisting of multiple small steps. If you want your company to be more remote-friendly it is also not all-or-nothing decision. You can gradually start using techniques that will bring you closer to your goal. This series of blogposts is not about why you should go remote, but rather how. Also, we belive that those techniques will help you even if you are not planning to work remotely.

The first part was about having very small stories and how it helps everyone track progress and provides closure. Today we are going to talk about leaving tasks unassigned instead of delegating them to particular developers at the beginning of an iteration.

continue reading →

Services - what are they and why we need them?

Model-View-Controller is a design pattern which absolutely dominated web frameworks. On the first look it provides a great and logical separation between our application components. When we apply some basic principles (like ‘fat models, slim controllers’) to our application, we can live happily very long with this basic fragmentation.

However, when our application grows, our skinny controllers become not so skinny over time. We can’t test in isolation, because we’re highly coupled with the framework. To fix this problem, we can use service objects as a new layer in our design.

continue reading →

Throw away Sprockets, use UNIX!

The Sprockets gem is the standard way to combine asset files in Rails, but it wasn’t very straightforward to use in stand-alone projects, like Single Page Applications without backend, before the sprockets command was added.

Few weeks ago I realized that Sprockets solve the problem that has been already solved, but in a different language and in different era of computing.

Later I wanted to check whether my idea would actually work and started hacking. You can see the results below.

continue reading →

Developers oriented project management

Working remotely is still a relatively new thing compared to going to an office, which has centuries long tradition. Despite its tremendous growth recently (especially in IT industry), there is not a lot of literature about best practices and working solutions. We still miss patterns for remote collaboration.

Many companies try remote working, but fail at doing it effectively.

They go with the conclusion that it is a broken model. But the truth is, that working remotely is just different, and expecting it to be the same as stationary work, with just people in different places, is the biggest mistake that one can made about it. To fully benefit from it, one must learn how to get most out of it.

You need to learn how to embrace remote work, instead of working around it.

On the other hand, some companies are already there, when it comes to remote working. Or at least they think they are. But is there something more that we can strive for? More ideas that we can try and benefit from? Many of them.

continue reading →

CoffeeScript tests for Rails apps

You may know this pain too well - you’ve created rich client-side in you Rails app and when your try to test CoffeeScript features it consumes much time to run all test scenarios with capybara and any of browser drivers (selenium, webkit, phantomjs). Let’s apply painkiller then - move responsibility of testing front-end to… front-end.

continue reading →

Ruby and AOP: Decouple your code even more

We, programmers, care for our applications’ design greatly. We can spend hours arguing about solutions that we dislike and refactoring our code to loose coupling and weaken dependencies between our objects.

Unfortunately, there are Dark Parts in our apps - persistence, networking, logging, notifications… these parts are scattered in our code - we have to specify explicit dependencies between them and domain objects.

Is there anything that can be done about it or is the real world a nightmare for purists? Fortunately, a solution exists. Ladies and gentlemen, we present aspect-oriented programming!

continue reading →

Implementing worker threads in Rails

If you care about your application performance you have to schedule extra tasks into background when handling requests. One of such tasks may be collecting performance or business metrics. In this post I’ll show you how to avoid potential problems with threaded background workers.

continue reading →

The A Team

I work in Arkency for almost 4 years and lately I’ve started to think how it influences me. Working together is not only about delivering some good as a bunch of people - team has own identity, own culture. These days I decided to write down what I found out about my team for two reasons. First is just to see some day how it evolved over years - but that’s a good reason to write it in “My sweet diary”, holden under a pillow. I’m also inspired by great blog series “We are principled” by 8th Light.

continue reading →

Is it cute or ugly?

Yesterday day I presented a small code snippet to my dear coworkers (who I of course always respect) and (as usually) they were not impressed, even though I liked my solution. So I wanted to know your opinion about this little piece of code. Let’s start with the beginning.

continue reading →

Naming in OOP

There is a well known cite on naming in our industry:

“There are only two hard things in Computer Science: cache invalidation and naming things.” Phil Karlton

To be honest it’s not Computer Science specific issue, but common problem for whole science. History of science is composed of discoveries and evolution of definitions. Every math theorem is based on some definitions - I would call it “theorem dictionary”. There is also huge branch of philosophy aiming to figure out how our language infleunce on our thoughts. So I asked myself - how naming can influence my design. What can I learn from bad names?

continue reading →

Black-box Ruby tests architecture is distributed - currently just as few processes on same production server. As professionals we decided to prepare integration tests for each of application (maybe in terms of their business we could call them acceptance tests), but that wasn’t enough - we wanted to expose business scenarios that we’re actually aiming in. We achieved that with fully black-box tests. Curious how we did that? Read on.

continue reading →

Rails API - my simple approach

I have seen people using very different techniques to build API around Rails applications. I wanted to show what I like to do in my projects. Mostly because it is a very simple solution and it does not make your models concerned with another responsibility.

continue reading →

You don't inject for tests

What is unit testing for? Is it a way to make sure that your code is correct and bugless? Or rather OOD tool, that expose most of places where you break object orientation principles? You may have your own answer (please comment though) but I would vote for the second one - of course it may assure me that I haven’t introduced some totally stupid bug, but that’s less interesting part.

continue reading →

Blogging for developers

There are many possible blogging platforms out there to be used, yet we decided not to use any of them. It was a controversial decision even inside our own, small team. Before we started blogging there was a heated discussion whether we should use something that can quickly get you running so that when you feel in a mood for a blog post, there are no obstacles preventing you from writing. Or the alternative was to build something custom and have more control. We ended up using existing tools but put a little effort to combine them together into something that we like.

continue reading →

Sending async data from Rails into the world

Exceptions and business metrics. These are two common use cases involving delivery of data from our Rails application (or any other web application) to external services that are not so crucial and probably we would like to send them asynchronously instead of waiting for the response, blocking the thread. We will try to balance speed and certainty here, which is always a hard thing to achieve.

This is a series of posts which describe what techniques can be used in such situation. The first solution that I would like to describe (or discredit) is ZMQ.

continue reading →

JavaScript objects philosophy

As a web programmer you use JS from time to time or on daily basis. You probably know how to create and use objects, but don’t feel that approach is natural. It’s awful JS, right? No, it’s you and your lack of knowledge. Let’s see what object orientation in JavaScript mean.

continue reading →

Filepicker and Aviary - Image uploading on steroids

We all have been using the same code for uploading images for years, but didn’t you always feel that there is something wrong with it? For every other task like writing texts, picking a date, selecting from lot of choices we have a good tool that can help in implementing such feature and improve the user experience, but file uploads almost always feel a little broken. There are some Flash tools that might help, but they are still not good enough.

continue reading →