Frontendrails logo Front End Rails

Prototypes in Ruby and the strange story of dup

Prototypes in Ruby and the strange story of dup

Arkency Arkency 07 March 2017

Today I was working on a feature where I had to create a few similar Active Record objects. I was creating a read model for some financial data. Most of the attributes of created objects were the same but a few were different. In one refactoring step I removed the duplication in passing attributes by using a prototype. Although at that moment I haven't thought of the object in such way.

Ruby code I no longer write

Ruby code I no longer write

Arkency Arkency 17 February 2017

When we learn programming languages and techniques we go through certain phases: Curiosity Admiration Overdosage Rejection Approval etc. Similarly with other things we enjoy in our life such as ice cream, pizza and sunbathing :) We learn to enjoy them, we try too much of it and learn the consequences. Hopefully some time later we find a good balance. We know, how much of it, we can use without hurting ourselves. I think we can have a similar experience in programming for example when you find out about metaprogramming, immutability, unit testing, DDD. Basically anything. We often need to hit an invisible wall and realize that we overdosed. It's not easy at all to realize it and learn from it. After 8 years of using Ruby and Rails, there are certain constructs that I try not to use anymore because I believe they make maintaining large applications harder.

How to unit test classes which depend on Rails models?

How to unit test classes which depend on Rails models?

Arkency Arkency 05 February 2017

Let's say you have such a class: (this code is borrowed from this Reddit thread ``` !ruby class CreateSomethingService def initialize(params) parse_parameters params end def run Something.create(name: @name) end private def parse_parameters(params) @name = params[:name] end end ```

Fluent Interfaces in Ruby ecosystem

Fluent Interfaces in Ruby ecosystem

Arkency Arkency 26 January 2017

You already used fluent interfaces multiple times as a Ruby developer. Although you might not have done it consciously. And maybe you haven't built yourself a class with such API style yet. Let me present you a couple of examples from Ruby and its ecosystem and how I designed such API in my use-case.

Why Smalltalk instead of Ruby

Why Smalltalk instead of Ruby

Arkency Arkency 20 January 2017

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! :)

Run your tests on production!

Run your tests on production!

Arkency Arkency 13 January 2017

Running your tests on “production”? On the real, live system? Sounds unorthodox? There might be situations, where it’s actually a good idea. Read on!
On upcoming immutable string literals in Ruby

On upcoming immutable string literals in Ruby

Arkency Arkency 02 January 2017

Today I checked one of the solutions made by our Junior Rails Developer class student. As part of the course they make Rails apps but also learn from smaller code examples delivered by exercism.io. I found there an opportunity for him to learn more about a few things...

Event sourced domain objects in less than 150 LOC

Event sourced domain objects in less than 150 LOC

Arkency Arkency 30 December 2016

Some say: "Event sourcing is hard". Some say: "You need a framework to use Event Sourcing". Some say: ... Meh. You aren't gonna need it.

Patterns for dealing with uncertainty

Patterns for dealing with uncertainty

Arkency Arkency 04 December 2016

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.

Testable Javascript with pure functions

Testable Javascript with pure functions

Arkency Arkency 28 November 2016

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.

Dealing with randomly failing tests from a team perspective

Dealing with randomly failing tests from a team perspective

Arkency Arkency 20 November 2016

One of the things that can negatively impact a team morale is random builds - builds where sometimes some tests are failing. Inspired by Martin Fowler's article on Quarantine, in some of our projects we came up with a guideline how we can fix the problem as a team.

One request can be multiple commands

One request can be multiple commands

Arkency Arkency 16 November 2016

It took me many years to understand the simple truth. One HTTP request sent by a browser may include a few separate logical commands. One request does not always equal one logical command.

Ruby exceptions are 4400 times faster than ActiveRecord::Base#create

Ruby exceptions are 4400 times faster than ActiveRecord::Base#create

Arkency Arkency 09 November 2016

How slow are Ruby exceptions as compared to other frequent actions we may be doing in Rails apps. Like for example, as compared to ActiveRecord::Base#create

Rails and adapter objects: different implementations in production and tests

Rails and adapter objects: different implementations in production and tests

Arkency Arkency 06 November 2016

If you work with service objects in Rails apps, very quickly you need to have the dependency being passed to the service object constructor. Which usually means, that the Rails controller needs to do it. This blogpost describes how to have a different implementation being passed in the production environment and an in-memory one in the tests.

The typical Ruby bugs with changing the last line in a method

The typical Ruby bugs with changing the last line in a method

Arkency Arkency 27 October 2016

In Ruby, we don't have to type return at the end of the method. As many other things in our favourite language, this is implicit, not explicit. The value of the last line in a method is also automatically the value of the whole method. Which is a good thing as it helps making the code less verbose and more poem-like. But it also has some dangers.