Review: Design Patterns in Ruby

Posted by Jonathan

Design Patterns in Ruby by Russ Olsen is an introduction to Design Patterns. It covers 14 out of the 23 patterns of the GoF Design Patters: Elements of Reusable Object-Oriented Software book and adds three Ruby-related patterns. The book examines each pattern in general, shows how it applies to a dynamic language like Ruby and explains when to use or not use the pattern.

The fact that the book is written in an informal style with lots of examples makes it really easy to read and follow. I really liked the format of the pattern examination and find it an excellent overview of and introduction to Design Patterns. The covered GoF patterns (Template Method, Strategy, Observer, Composite, Iterator, Command, Adapter, Proxy, Decorator, Singleton, Factory Method, Abstract Factory Method, Builder, and Interpreter) are the most important ones and are easy to apply in Ruby. Especially the chapter on Interpreter made a very good job of explaining a widely under-utilized pattern. It even showed how to build a parser and didn't stop at the AST.

Apart from those classic patterns, the book introduces Internal Domain-Specific Languages, Meta-Programming, and Convention Over Configuration as newer patterns that are closely related to dynamic languages like Ruby. Those chapters cover nothing new to Rails programmers but are a nice addition to a general Ruby Patterns book. In my opinion the discussion of Meta-Programming could be a bit longer as it only covers class_eval and Ruby has more to offer.

In general, Design Patterns in Ruby is a very good overview of Design Patterns in the modern, dynamic world of Ruby. The book makes sure that the reader understands where a pattern arises and is very good in explaining its usage by example. Further, I cannot praise enough the fact that the author also tells you when NOT to use a pattern and warns about over-usage of inheritance or patterns.

With 338 pages of informal, easy to read examples and explanations, the book is easy to read in two or three afternoons. If you look for an introduction to Design Patterns or want to know how they apply in Ruby, I really recommend Design Patterns in Ruby.

Patterns of Software Craftsmanship: From Apprentice to Journeyman

Posted by Jonathan

Dave Hoover lately began to describe a Software Development Pattern: The Apprenticeship Pattern.

Find Your Master -> Be The Worst -> Accurate Self Assessment -> Expose Your Ignorance

The main idea is that you as a software developer should always be searching for a “master”. Someone who knows more than you and from whom you can learn. Look how your master is working a learn from him. When you find yourself to be the best developer in a group, it’s time to change the group as your learning is likely halted or lessened. Strive to be the “worst” in the group because so you will learn the most.

I really agree with this pattern.

It’s like running. If you run against a better runner, you are likely to be faster than when you are running against a weaker opponent. Sadly I’m now often in a position where I am the best programmer in team and so the increase in learning is rather low. Dave Hoover created an overview of the apprenticeship pattern and divided it into three categories:

  • Relational Patterns: Surround yourself with exceptional developers.
  • Political Patterns: Prepare yourself for sacrifices, nurture your desire to excel.
  • Learning Patterns: Dedicate yourself to lifelong learning and technical excellence.

Similar thoughts can be found in the Pragmatic Programmer and in Extreme Programming Explained: Embrace Change. Two books that should be part of every programmers library.

Reminds me that courage, one of the four values of XP, is something we need in our current project. Horrible inherited code-base and I am the only one to dare rewriting everything.