Reviews: The Book of (Weird) Ruby, and Eloquent Ruby

No Starch Press is one of the better technical book publishers, like O'Reilly and The Pragmatic Programmers. It is offering a new book about Ruby called The Book of Ruby by Huw Collingbourne, the Technology Director for SapphireSteel Software (and, as far as I can tell, one of only two people in the company). SapphireSteel develops tools for Visual Studio, including a Ruby IDE extension to Visual Studio called Ruby in Steel, "the professional Ruby IDE" in the words of the SapphireRuby site. I'm a little skeptical of the value of Visual Studio integration for Ruby, but whatever floats your boat is good for you, I suppose.

Announcement and Availability

On the ruby-talk list, someone identified as Jon announced the publication of The Book of Ruby, something that has been included with the RubyInstaller for Windows for quite some time. Luis Lavena, the lead developer for the RubyInstaller project, informs me "'Jon' is one of the biggest contributors to the RubyInstaller project itself." For those unfamiliar with it, the RubyInstaller project has become the de facto "official" Ruby installation tool for MS Windows, and it works great for general usage. I have used RubyInstaller for occasions where I needed Ruby on an MS Windows system with no complaints, though until today I have not actually read any of The Book of Ruby; see my comments about reading PDFs on a laptop below for why.

While No Starch Press -- on its Book of Ruby page -- offers Chapter 11: Symbols as a free PDF download, Jon's announcement of Huw Collingbourne's book includes a URI for a free download of Chapter 10: Blocks, Procs, and Lambdas as well. There is a link to that download on the RubyInstaller site's homepage as well.

In addition to that, a discount code worth 30% off the cover price of $39.95 when you buy the book at the No Starch Press site is offered: RUNREADRUBY

As one response on the ruby-talk list pointed out, Amazon offers the same book for $26.37, which is about $1.60 lower than a strict 70% of the cover price, so it is a cheaper purchase at Amazon. I do not recall the shipping rates when buying from No Starch Press, but I do not think the rate is "free", whereas Amazon offers "Super Saver Shipping" (that is, free shipping) for most orders over $25. On the other hand, when I checked today, there was only one copy of the book left in stock at Amazon.

As a nice compensation for that $1.60ish plus shipping, though, No Starch Press offers free access to EPUB, Mobi, and PDF ebooks when buying the book there (and any other hardcopy book purchases there, I think). I own an ebook reader now, as you might know from An Open Letter To Barnes & Noble About Text Files -- a Barnes & Noble Nook Simple Touch Reader -- and as such, ebooks that come with the purchase of hardcopy are very tempting to me, especially that EPUB format. I would like plain text even more if my Nook supported plain text; see my Open Letter for more details about that travesty of technology design.

Even without the Nook, though, I would consider it worthwhile to have a searchable PDF on my computer in addition to the hardcopy on my shelf. Being able to carry it around on my smartphone, if I needed to quickly look up something while I'm away from both my Nook and my laptop, would be nice too. Offering it in all three of those formats is a nice touch of class from No Starch Press. I started to think I should get this book, even though I was not thinking of getting another Ruby book any time soon before that announcement on ruby-talk; I already have eight (or so) Ruby books, counting hardcopies and an ebook on my Nook, and not counting PDFs on my laptop because I find it very difficult to read a "book" on a laptop and big PDFs are annoyingly slow and sometimes slightly broken on my Nook. Big PDFs tend to serve only as reference on my laptop, rather than really readable books.

Because Amazon offers only a very limited number of copies of The Book of Ruby at a price that is not much cheaper than the No Starch Press store's price, and offers no ebook formats of it at all (not even for the Kindle, which I do not own anyway), and because of the discount code and free ebooks when buying from No Starch Press, I was about ready to pull out my wallet and buy it. There was another response to the ruby-talk list announcement that reminded me to be cautious, though. In it, Steve Klabnik said that the author's code style in the book was unlike anything one would be likely to see anywhere else in Ruby. I decided to investigate the matter by downloading one of the free chapters and forcing myself to overcome my distaste for PDF ebooks (or PDF echapters in this case).

The Book of Ruby Review Itself

After downloading and perusing Chapter 10, thinking at first "Well, it probably isn't that bad," I discovered that it is, in fact, that bad. This code is an example of what I found:

["hello","good day","how do you do"].each{
    caps( s ){ |x| x.capitalize!
        puts( x )

I find this (relatively) hard to read and, contrary to the explanation the author uses to justify his departures from idiomatic Ruby style, inconsistent. I spent about ten minutes thinking about, and refreshing my memory of, idiomatic styles for other languages, with Google as my guide; I was trying to figure out what language might have been the foundation for this author developing the style he uses. I thought maybe he was doing something like writing C++ in Ruby (as an example -- despite the wide range of styles considered "idiomatic" for C++, none of which I am aware exactly fit the bill). I have not yet come up with a language whose idiomatic style could explain this. If any readers can offer a suggestion, I would love to hear about it. Another clue to the origin of the author's style might be found in this code sample:

x = "hello world"

ablock = { puts( x ) }

def aMethod( aBlockArg )
    x = "goodbye"

puts( x )
aMethod( ablock )
puts( x )

Notice the inconsistent use of camelCaseWithoutLeadingCaps, parentheses for all arguments in all circumstances, four-space indents (as opposed to Ruby's idiomatic two), and from the previous sample the tendency to use braces without preceding spaces while splitting blocks across multiple lines, bumping block arguments to the next line sometimes (but not always), and occasional inclusion of the first line of code in a block on the same line as the opening brace. I count at least four violations of idiomatic Ruby style just in the way the author uses braces for Ruby blocks.

The book does get some technical issues more precisely on-target than most other books (e.g., a definition of closures that is disguised as an off-hand, conversational throw-away commentary on closures) -- stuff that other books do not necessarily get wrong, but do tend to describe imprecisely in a way that ends up being misleading -- but it trades these items of relatively precise accuracy for others where the use of terminology appears to be misused or at least inconsistently applied, such as the way the author uses the terms "block" and "method" incautiously.

If the code style works for the author and his collaborators, great. It is not, however, code that would encourage me to contribute to the project if I came across it on Bitbucket or GitHub, and within the context of the book I find it distracting. As Steve Klabnik pointed out, you are not likely to encounter this coding style in the wild; it is distinctly un-idiomatic, and does not appear to even conform to any reasonably consistent rules of style at all. It could easily lead the reader astray; most idiomatic stylistic choices in Ruby carefully emphasize things that need emphasis in source, make things more readable within the context of Ruby syntax, and encourage good coding practices, to say nothing of the fact that having a thoroughly alien style relative to the idiomatic style of the language's community makes one a less desirable and effective contributor to others' projects.

As for the content of the book itself, I do not find that it presents any perspectives on the topics it addresses that are new to me, from what I have read so far. In fact, everything that is not superficial departure from norms without any good reason that I can find appears to be boringly conventional and uninteresting. This is fine for a beginner in the language who just wants to build a solid understanding of the language, but not for someone who has been using the language for a while and become comfortable with its basics already. Its possible value for a beginner, in my estimation, is badly undermined by its departures from idiom and even from the author's own explanations of his preferred style and the reasons he chooses to use that style.

I understand that the RubyInstaller project promotes The Book of Ruby to some extent because it was the best available option for distributing a Ruby book with RubyInstaller, and do not fault them for that. This does not mean I think it is the book a beginning Rubyist should use as an introduction to the language, however.

By Contrast, Eloquent Ruby

If you want a book well-suited to familiarizing the beginning Rubyist with the fundamentals of the language and common practice, as well as an introduction to the effective use of tools and techniques that are useful to Rubyists, I would recommend Russ Olsen's Eloquent Ruby, also available for the Nook at a very reasonable price. The prices are better for Barnes & Noble members, of course. Amazon might offer better prices for non-members.

I feel Eloquent Ruby does a better, more consistent job of explaining the concepts it addresses, covers things in a more approachable manner, and does not throw all idiomatic convention out the window for no (apparent) good reason. Also important, in my case, is the fact that even for a Rubyist with a couple of years or so under his belt already it still has something to teach the reader. It even provides a useful, if brief, introduction to test-driven development with both Test::Unit and RSpec.

Russ Olsen did a great job with his book, and I do not feel the same about Huw Collingbourne's effort at all -- even if the latter's book does have a cool ninja motif on the cover and come with free ebooks. In the case of Olsen's book Eloquent Ruby, I had to either choose between formats or spend more money than I was willing to spend on the text. Living with that choice, however, is much easier than living with the mistake of paying real money for a book whose content follows the patterns I saw in the sample chapters for The Book of Ruby.


Thanks to Luis Lavena for offering feedback on my review, allowing me to better clarify some of what I intended to say.