Rails AntiPatterns Book Review
With Ruby on Rails firmly entrenched in the web application development scene, books on the subject are migrating from introductory tutorials to deeper, more advanced studies on the topic. Rails AntiPatterns: Best Practice Ruby on Rails Refactoring is one such book. Does its educational value match its cover price? Read on to find out.According to the Chad Pytel and Tammer Saleh, the book's authors who base the definition's source on an earlier AntiPatterns title, an AntiPattern is "a repeated pattern of action, process, or structure that initially appears to be beneficial but ultimately produces more bad consequences than beneficial results". An AntiPattern must also have "a refactored solution that is clearly documented, proven in actual practice, and repeatable." Essentially, Rails AntiPatterns is a variant on the Problem/Solution technical cookbooks that focuses on frequent issues and bad habits that developers unintentionally bake into Rails projects. This ten chapter book dives into all aspects of Rails development and deployment where such AntiPatterns show up.
The first chapter, the largest in the book, hits the ground running with Model AntiPatterns: Voyeuristic and Fat Models, Spaghetti SQL and Duplicate Code Duplication. Domain Modeling explores two AntiPatterns: Authorization Astronaut and The Million-Model March. Chapter 3 on Views coves PHPitis and Markup Mayhem. Controllers presents eight AntiPatterns including Bloated Sessions, Rat's Nest Resources and Evil Twin Controllers. Chapter 5 on Services contains five services-related AntiPatterns such as Pitiful Page Parsing and Successful Failure. The chapter on Using Third Part Code offers four AntiPatterns, Chapter 7 (Testing) has five such as Fixture Blues and Unprotected Jewels and Chapter 8 (Scaling and Deploying) discusses four more, such as Disappearing Assets and Sluggish SQL. Chapter 9 contains two Database Antipatterns (Messy Migrations and Wet Validations), and the final chapter (Building for Failure) offers up two more AntiPatterns (Continual Catastrophe and Inaudible Failures). Each of the 38 AntiPatterns follows the same AntiPattern/Solution format, first discussing the AntiPattern in detail including the reasons and outcomes of the problem followed by a often deeply technical exposition on the solution.
The book works on a number of levels. First, anyone who has been writing Rails applications beyond small departmental one-offs has encountered at least a few of the AntiPatterns identified by the authors. While you could spend hours on Google searching for a solution (assuming you know exactly what your problem is and the question that needs to be asked), knowing these patterns up front could save a lot of time, hair and sanity. Second, the authors obviously have deep knowledge of and passion for Rails, and this translates well on the page. They empathize with the readers, recounting from their own AntiPattern wrestling matches how these problems can really put a damper on your Rails productivity and enthusiasm. And most importantly, unlike various problem/solution cookbooks written by many contributors, Rails AntiPatterns maintains a comfortable and colloquial conversation with the authors. I pictured them speaking with me during the lobbytrack of a Rails conference over problems they encountered and the introspective solutions they discovered. Sharing these with the readers, especially the ones about fixtures and failures ("never fail quietly"), were most memorable.
Beginning Rails developers might not be able to fully appreciate the insights the authors share, but intermediate and advanced Rails programmers will be nodding their head in some sections, saying 'so that's why' in others and thinking 'oh, that's something I'll have to remember to avoid' while reading several more. Dedicated Rails developers should not hesitate adding Rails AntiPatterns to their bookshelf.
Title: Rails AntiPatterns: Best Practice Ruby on Rails Refactoring Authors: Chad Pytel and Tammer Saleh Publisher: Addison-Wesley Professional ISBN: 978-0-321-60481-1 Pages: 400 Price: $35.99 (Ebook), $44.99 (Print)