dimanche 10 mars 2013

Practical Object-Oriented Design In Ruby




Crafting well designed software artifacts is tremendously difficult. As for most engineering activities, making the right choices is best achieved with the help of a wise and insightful guide. Practical Object-Oriented Design in Ruby is exactly such a guide.

The book brings the reader in a smooth journey into the realm of software design using Ruby, a dynamically typed object-oriented programming language. The book motivates and illustrates a fair number of programming design rules. The book innovates on essentially two points. First, it largely discusses the benefits of using a dynamically typed language. It presents "duck typing" as  a valuable asset to reduce development cost. Second, it highlights how Ruby's module nicely complements single class inheritance for a better productivity.

Unit testing is presented at the end of the book, in the last chapter. In my opinion, testing could have been introduced much earlier since most of the examples given in the book come with an expression to illustrate the intended behavior of the code. Such expression can perfectly be embedded in an assert, turning an ad-hoc expression into an automatic and repeatable scenario. In addition, unit tests are a wonderful tool to identify the right interface for objects, especially when compared with UML sequence diagrams.

Ruby, as well as most programming languages, offers a reflective mechanism which includes keywords such as kind_of?, is_a? and responds_to?. it is widely knows that using these introspective facilities reflect a fragile programming style. Although their use is not particularly advocated by the author, how to avoid using them is hidden behind the notion of polymorphism without being more precise. The double dispatch pattern has been proposed to not need to know more about the object identify than the strict necessary. I wish Sandi would have emphasized this point.

Leaving these two critics aside, Practical Object-Oriented Design In Ruby is well written. Chapters are well balanced with the right amount of examples, experience relating and theory. The writing style is both entertaining, easy to follow and accessible (I am here thinking about non-native English readers).

Although primarily written for Ruby programmers, fans of another programming language will  found valuable material. Beside Chapter 7, which is about sharing roles behaviors using Ruby modules, all the remaining chapters are pretty much loosely tied to Ruby. 

The book does not target people who wish to learn Ruby. Instead, it focuses on seasoned programmers who want to fine tune their design skills. Practical Object-Oriented Design In Ruby will nicely complement a reference on design patterns.