Petri Wessman's weblog

Minireview: Rails Antipatterns, by Chad Pytel and Tammer Saleh

Ruby on Rails, nowadays sporting a major version number of 3, has become one of the more popular web development platforms – for good reason, in my opinion. The design is quite elegant, and the emphasis on “convention over configuration” lets you design apps with surprisingly few lines of code. Also, being based on Ruby gives it another layer of elegance (again, in my opinion).

However, all this seeming simplicity hides the fact that both the language (Ruby) and the platform are actually quite complex, underneath the simple exterior. Things work well if the designer follows the Rails (and Ruby) conventions and has at least some understanding of how a web app stack works. Unfortunately, in reality all too many programmers try to use Rails to emulate what they are already familiar with (PHP, in many cases), and even “professional programmers” seem to sometimes have only the faintest idea of how web apps actually work underneath the hood. The result can be a horror show.

Which brings us to this book, Rails Antipatterns. While it’s nominally about Rails “antipatterns” (design patterns that should not be emulated), it’s more properly a book about best practices and refactoring Rails apps. Written by people with extensive and painful knowledge about the horrors involved, it contains a ton of useful advice about how to (and how not to) design Rails apps. Each section focuses on a certain area of the software stack, and highlights the most common mistakes (and how to fix them).

I found it to be a great read, and even though Rails itself is nearing the publication of version 4.x at this point, virtually all of the advice within still holds true (the tiny part that doesn’t is the stuff about plugins, which are being phased out completely). If you already know Rails to some extent, this book will probably teach you a thing or three. If you don’t, you’ll be better of first reading some intro text and doing some coding of your own, and then going back to this book to see all the ways you screwed up.

As always with power tools, Rails only works properly if you know how to use it, and a large part of that is conventions, best practices and other not-initially-obvious design factors.

I personally most enjoyed the section on how to “thin down” a “fat” controller action, using ActiveModel callbacks and other related tricks. I used the advice here to refactor some of my own code with similar problems, and the end result was much cleaner.

Published on by Orava, tags , , , ,

comment Minireview: Rails Antipatterns, by Chad Pytel and Tammer Saleh

Trackbacks are disabled

Powered by Publify – Thème Frédéric de Villamil | Photo Glenn