Practical Object-Oriented Design in Ruby by Sandi Metz is on the short list of excellent software development books I have read. It falls into a very nice place of being a great book on OO Design, plus some interesting ruby tips. I would recommend it for non-ruby developers who would like to see some great step by step OO design via refactoring. The book is an easy read due to the fabulous conversational tone Sandi uses, and the examples feel just complicated enough to make her points without being too simple. It feels like a book I’ll read multiple times between the ease of reading and the wealth of good information.
The top 4 items I found interesting in the book were:
1. In chapter 3 (Managing Dependencies), the section that lists basic types of dependencies was eye-opening. I would not have thought of parameter ordering as a dependency due to my background having more hours of programming in statically typed languages. The solution was obvious (a hash of arguments with keys for each parameter), and one I have used in the past. However, I know in some of the fun projects I have done this became a small pain point for me that I never naturally made this jump to, but now feel like a fool for not doing so.
2. In chapter 4 (Creating Flexible Interfaces) the discussion of the Law of Demeter was interesting. The caveat around list manipulation in ruby was the point I found most interesting. The caveat was around code like hash.keys.sort.join(‘, ‘), which are common ruby style, and is clearly a violation of a “strict” interpretation of Demeter. Sandi appropriately points out that at best this is a light violation, and trying to avoid the violation will likely have higher cost.
3. In chapter 8 (Combining Objects with Composition) the discussion of Inheritance vs Roles with Modules vs Composition was superb. Is-a, behaves-like-a, and has-a are simple concepts, but Sandi explains them very well. Roles using modules is not in the classic OO inheritance discussion, but clearly for ruby it is a powerful techniques of code reuse.
4. In chapter 9 (Designing cost-Effective Tests) the discussion of testing of class hierarchies using test modules was very education. The whole section on testing is great (and see her talk about the testing to get a feel for most of the chapter), but the testing of interfaces is superb. It is another item that seems obvious in retrospect (use a module to test that a class supports the expected interface), but was new territory for me.