Review of

Programming Ruby: The Pragmatic Programmer's Guide, Second Edition

by Arien Malec




By Dave Thomas, with Chad Fowler and Andy Hunt 
2nd Edition Oct 2004 
ISBN: 0-9745140-5-5



Ruby was born in Japan, created by Yukihiro Matsumoto ("Matz"), and has recently created a small following in the US (most notably with Smalltalk programmers, who are right at home with the design philosophy underlying Ruby). It has gained more exposure of late due to the Ruby on Rails web application framework; it may well be worthwhile to learn Ruby just to evaluate Rails seriously. If nothing else, Rails is an excellent example of creating an application framework that fits tightly with the development language. It may also be worthwhile to learn simply to absorb the design choices Matz has made with Ruby (particularly for those Python programmers who have not already learned Smalltalk).


The first edition of this book, by the Pragmatic Programmers, Andy Hunt and Dave Thomas, was widely and justly considered the best English language introduction to Ruby (it has been donated by the authors as a freely available on-line edition). This new edition (mainly re-written by Dave Thomas, but keeping Andy Hunt's name on, and adding Chad Fowler, who wrote the section on package management with RubyGems) has been heavily updated to incorporate core language and library changes to Ruby.


The first section (especially the first 10 chapters) are a very well done grounding in the fundamentals of Ruby, diving very quickly into the heart of Ruby. There is a lamentable tendency in many programming language introductory texts to spend absurd amounts of time on simple fundamentals (variable syntax rules, simple data types, control statements, etc.); "Programming Ruby" goes back to the tradition started by Kernigan and Ritchie's "The C Programming language" in which the language is taught by showing useful programs that illustrate how to program idiomatically in the language. One learns not just how to make Ruby programs, but how to program Ruby; that is, how to solve programming problems using the tools and idioms natural to Ruby. The native Ruby unit testing framework gets its own chapter in this section, keeping with the authors' interests in agile development. The first edition had a quite nice explaination of how to build your own iteration methods (Ruby's Smalltalk inspired equivalent to Python's generator expression); this is completely missing from the second edition. Perhaps this is because the example used in the first edition, an implementation of Smalltalk's inject method, is now incorporated as a core part of Ruby, but the omission of a good concrete example of how to build an iteration method taking a block is a real loss.


The second part of the book covers Ruby libraries for documentation, package management, windowing (with Tk), web programming, interfacing with Windows, and extending with C. Each chapter in this part is tightly focused, and well done, giving useful examples and a good reference to the underlying tools.


The third part of the book gives a very deep dive into how the Ruby language is put together. It provides a language lawyer overview of Ruby, and covers deep topics in classes, method and modules. Among the highlights are an introduction to Ruby metaobjects (which are slightly less powerful than the fully Python implementation of the Lisp/Smalltalk Meta-Object Protocol [MOP]), and a description of extending the Module and Kernel objects to provide some equivalent power to the full MOP. I plan to re-read this part several times; it is not the sort of material which is fully absorbed in one reading.


The fourth part (fully half the book) is an overview of the Ruby core and standard library. Much of this is simply a printed repetition of the core library documentation, but perhaps this is just, given that Dave Thomas wrote RDoc, which is used to produce the online core library documentation. The standard library documentation is a useful brief overview of each library with example usage, but without exhaustive documentation of each class and method. In my opinion, that would have been a much better approach to the core library documentation as well, both saving trees, and enhancing the usability of the printed book. This custom of printing full library documentation made sense when network connection was neither fast nor ubiquitous, but makes little sense today.


In summary, this is a very well written and quite complete introduction to the Ruby language, highly recommended for any Python programmer who wishes to pick up Ruby. Its strong points are its teaching through examples, its exposing readers to thinking in Ruby, and its deep treatment of language topics. Its weakest point is the mostly needless bulk introduced by the reprinting of the online core library documentation.