Book Review: Humble Little Ruby Book

After reading the very first paragraph of Mr. Neighborly’s Humble Little Ruby Book (HLRB for short, from now on) it was very clear to me that it was going to be quite an unconventional read:

“Yes, there is a Chapter 0. There is a little bit of introductory stuff we need to talk about before
we set you loose on Ruby. You wouldn’t want to get psyched about a new gadget, get it home,
and then figure out you need batteries, a grapefruit, and the ability to speak three languages to
even open the box would you?”

That reminded me immediately of Why’s Poignant Guide to Ruby. without a doubt. I don’t know how it is possible that two witty, crazy, and very inventive guys grew fond of the same programming language. Anyhow, to reassure a few of you, you won’t find any foxes or chunky bacon cartoons in HLRB, just some very well made (although still pretty unconventional) diagrams like this one:

Got the picture? Good. Let’s move on…h3. Chapter 0: What’chu talkin’ ’bout, mister?

Chapter 0 is like an introduction to the book and a place to put all the boring stuff you have to talk about in a book about a programming language:

  • What is Ruby?
  • Installation procedure (on Windows, Mac OS X and Linux)
  • Hello, World!

Yes, you can skip this one safely without losing too much, unless of course you still need to install Ruby on your machine.

Chapter 1: Welcome to Ruby.

“This section aims to introduce the syntactic sugar and linguistic misfortunes of Ruby in the
quickest manner that will still allow for a full education on the subject.”

As the first two lines of this chapter say, it’s time to learn the basics of Ruby. You’ll be quickly guided through strings, numbers, collections and variables. Every section with tons of code examples for your to play with. You won’t find a full list of all the 876 methods of the String class, but you’ll certainly learn the 10 most common ones at least (numbers are random, so no, don’t count them).
Sure, yes, right, whatever… if you really want you can skip this chapter too, but if you are already a Ruby Guru there’s probably no need for you to read books about Ruby, right? Beginners need to read this chapter. It’s compulsory, really, and pretty enjoyable, too.

Chapter 2: Break it down now!

Or “learn how to segment your code” using methods, and… blocks & Proc objects! Gosh. Our poor newbies will probably have a heart attack if they never heard about blocks and closures before. I almost got scared myself, because this is normally regarded as a pretty tough topic. Despite, at page 25 of the book you’ll have to face your fears and dive into it. You’ll survive, anyway.

Purist Warning: Please be aware that sometimes the author may decide to use certain terms and construct which may not sound 100% right to your ears. Just move on, beginners will understand more things like “Think of Proc objects as blocks that are pushed into variables.” than anything else, guaranteed.

After this section you’ll finally be introduced to Ruby classes. Now, this can piss someone off, no doubt. Ruby is a fully OO language, so people must learn about classes before anything else. I must admit I was a bit confused by the ordering of the topics at first, but if someone comes from a non-OO background he’ll probably find this particular order more suitable.
This section will cover class and object basics in Ruby like defining classes, instantiating objects, access control, methods, attributes, scope, duck typing. Finally, you’ll briefly look into modules as well.

Chapter 3: Hustle and flow (control)

Finally, the author will deal with flow control. So things like if, case, conditional operators, loops and statement modifiers. In my opinion this section is truly excellent: it introduces all the control structures in a very simple and crystal clear way, often using flowcharts. A great chance even for absolute beginners to understand these basic but powerful concepts.
Towards the end of the chapter, you’ll also learn how exceptions work: a clever way to tell people “you have to learn how to use exceptions from the very beginning”. Really nicely done.

Chapter 4: The system beneath…

Here comes the juicy stuff. Up to now you learnt the usual boring things you need to know when learning a new programming language, now finally you learn how to do real things. The chapter is full of complete and meaningful code snippets which will answer nearly all the questions you may have (at this time):

  • How do I read and write to a file?
  • How do I handle threads and processes?
  • How do command-line parameters and environment variables work?
  • How can I perform specific Windows-only operations, like reading and writing to the Registry? What about OLE automation?

Some of the big books out there will not spend too much time talking about Windows-only libraries, but I found HLRB gives quite a comprehensive introduction about them.

Chapter 5: Looking beyond home

More juicy stuff. If you are looking for a tutorial to learn the basics about networking, from from sockets to FTP to POP and web services, look no further: this chapter does a very remarkable job introducing various network-related libraries, with the usual well written code examples.
If that’s still not enough, you’ll also have a chance to explore the wonderful world of distributed Ruby and of databases. Granted, this chapter won’t tell you about the 1567 methods available in ActiveRecord (buy a copy of Agile Web Development with Rails for this), but will tell you enough to get started.

Chapter 6: It’s a Library!

The final chapter will go more in depth on some more advanced topics, like:

  • Strings
  • Regexp
  • Date & Time
  • Hashing and Cryptography
  • Unit Testing

Everything with more and more useful code snippets.

The Appendices

Last but not least, a HUGE collection of links and resources to learn more about Ruby, and a quick digression on C/C++ extensions… not much, but enough to wet your appetite.

The bottom line

HLRB is not the only book you need to read about Ruby. It’s better to make this clear otherwise I’ll be hunted forever by Dave Thomas, Chad Fowler, DHH and all the other excellent Ruby hackers who also wrote very successful books (which I bought as well). HLRB is LITTLE and HUMBLE, after all: it doesn’t aim at becoming the official Ruby Bible anytime soon (although a bird told me it may get updated someday and include more stuff), but it is still a worthwhile reading.

And of course I came to the very end of this review without mentioning the most important thing: this little wonder is free. All you need is to register to InfoQ (for free) and grab your free copy. If you want you can buy a printed copy for just $9.95, if you feel in a good mood (please do).

The most obvious strengths of this book are the abundance of code examples and very useful working snippets, and the unconventional style which makes it very readable and not boring at all. If I were to name some of its weaknesses (but only if you force me to), I’d say some parts should be expanded and more info on other libraries should be provided… but you never know what the future will bring us!

Well done, Mr. Neighborly!