A Review of “Eloquent Ruby” by Russ Olsen – It Rocks!
Eloquent Ruby (Amazon.com - print & Kindle) by Russ Olsen is the first Ruby book I've read in its entirety within 24 hours; it's that good. That may be all you need to know before you buy a copy at Amazon.com, Amazon.co.uk or read it on Safari (if you have an account). If you want to learn more though, keep reading.
What Is "Eloquent Ruby"?
Eloquent Ruby is a book published by Addison Wesley and written by Russ Olsen (who also wrote Design Patterns in Ruby a few years ago). It clocks in at around 400 pages and has 31 chapters clocking in at around a punchy 10 pages each. Each chapter is titled as a guideline you should follow to write "eloquent" Ruby - things like Create Classes That Understand Equality and Write Code That Looks Like Ruby - and typically the claim is explained, some code examples shown and discussed, some real world examples pointed to, and that's it.
As with Design Patterns in Ruby, Russ adopts a chatty, familiar tone. Reading this book is like reading a book specifically written for you by a friend. He doesn't shoot off on many unnecessary tangents and he keeps the stories short and sweet but this book certainly couldn't be called dry.
The book is also notably short of egregious errors or omissions. Even when I don't read something with a fine-toothed comb on standby, I can usually pick out a laundry list of factual and grammatical errors or omissions (as both Obie Fernandez and my wife will attest) but Eloquent Ruby gave me little to chew on. I can only bring to mind a few spacing and formatting issues and only one true "error": a
> instead of a
< in a class definition on a single example.
Russ tries to remain neutral with his choice of Ruby implementations but the book seems to focus primarily on Ruby 1.9 (Ruby 1.9.1 specifically but that's just due to when he wrote it) while providing useful footnotes in the cases where there are differences to Ruby 1.8. No matter what Ruby implementation you're using, there's little to confuse you as most of it is very non-implementation and non-version specific.
I wholeheartedly recommend this book to anyone except those who, well, could have written a similar book themselves. The short punchy chapters make it a delight to read and gives the option of reading it merely 10 minutes at a time before bed or similar. The short chapters also make it useful as a reference if you forget how to do a certain thing like, say, use method_missing, even though it's not put together as a reference book at all. Lastly, this book is a must read if you're not confident with Ruby idioms and the best way to structure and lay out your code - Russ's approaches reinforce the current "standard" way to write Ruby and this alone is worth the price of admission.
Who Should Buy It?
- Any Ruby developer who doesn't yet feel like they're at guru level (that's most of us!)
- Anyone who wants to get a feel for the typically undocumented style, syntax, and structural standards of top Ruby developers.
Who Shouldn't Buy It?
- Anyone without a sense of humor or who doesn't like a chatty, familiar type of writing.
- Matz, Dave Thomas, Chad Fowler, Russ Olsen himself, and a few others.
- Anyone who's resistant to change and wants to keep coding Ruby "their way."
The chapter titles in Eloquent Ruby are useful enough to give you an indication of the level(s) it aims at and whether it would be interesting to you, so here goes:
- Write Code That Looks Like Ruby
- Choose The Right Control Structure
- Take Advantage Of Ruby's Smart Collections
- Take Advantage Of Ruby's Smart Strings
- Find The Right String With Regular Expressions
- Use Symbols To Stand For Something
- Treat Everything Like An Object - Because It Is
- Embrace Dynamic Typing
- Write Specs!
- Construct Your Classes From Short, Focused Methods
- Define Operators Respectfully
- Create Classes That Understand Equality
- Get The Behavior You Need With Singleton And Class Methods
- Use Class Instance Variables
- Use Modules As Name spaces
- Use Modules As Mixins
- Use Blocks To Iterate
- Execute Around With A Block
- Save Blocks To Execute Later
- Use Hooks To Keep Your Program Informed
- Use method_missing For Flexible Error Handling
- Use method_missing For Delegation
- Use method_missing To Build Flexible APIs
- Update Existing Classes With Monkey Patching
- Create Self Modifying Classes
- Create Classes That Modify Their Subclasses
- Invent Internal DSLs
- Build External DSLs For Flexible Syntax
- Package Your Programs As Gems
- Know Your Ruby Implementation
- Keep An Open Mind To Go With Those Open Classes
There's something for everyone and it gets progressively more advanced.
How to Get Eloquent Ruby
If you want a print or Kindle copy, head to Amazon.com, Amazon.co.uk, or your other favorite book retailer. If a PDF or EPUB file is more to your taste, InformIT has those for sale (currently for $28.79).