Musings of a code junkie

Book: Ruby Best Practices

Tagged review, book, ruby, and best practices

UPDATE: The Ruby Best Practices book is now fully available as open source. You can now have access to the book’s source and a PDF version, but seriously think about showing support and purchasing a hardcopy of your own. More info over at the Ruby Best Practices blog (Updated on 17/03/2010)

Ruby Best Practices Book Cover

After learning the basics of Ruby and feeling at ease with the language, it’s time to take it to the next level. It’s time to start writing code like the experts: the Ruby way. Ruby Best Practices is just the book to help you do that, with a friendly tone and lots of yummy code examples for you to chew on and learn.

Read on to find out what to expect from the book and for some reading tips (that I wish I had done) on how to make the most out of it.

Overview

Ruby Best Practices was written by Gregory T. Brown and comes at 298 pages. The subtitle “Increase Your Productivity – Write better Code” pretty much sums what the book is about: taking your Ruby skills to the next level by learning how to write code like the experts, thus increasing your productivity.

The book covers a lot of topics such as (but not limited to): designing beautiful APIs, testing and debugging your code, taking advantage of Ruby’s dynamic features, and how to maintain your projects.

The Price

Ruby Best Practices costs $23.09 on Amazon.com and £14.87 on Amazon.co.uk (around €16). You also get access to the online version of the book for 45 days from Safari Books Online.

Gregory Brown is also open sourcing the book, so you can download the chapters yourself for free to see if it’s worth buying. I think it is. You can get the chapters from the RBP Blog along with other high quality Ruby-related articles.

What You Get

At 298 pages, you get 8 chapters:

  1. Driving Code Through Tests – talks about code testing, mocks and stubs, and TDD.
  2. Designing Beautiful APIs – shows what Ruby features help you create elegant and easy to use APIs.
  3. Mastering the Dynamic Toolkit – explains Ruby’s many reflective capabilities and how to use them.
  4. Text Processing and File Management – tricks and tips to help you manage and process files.
  5. Functional Programming Techniques – goes through some functional techniques that can help you.
  6. When Things Go Wrong – mentions ways to hunt for bugs when your program explodes.
  7. Reducing Cultural Barriers – explains various methods to make your apps internationally friendly.
  8. Skillful Project Maintenance – shows you and explains how Ruby projects are typically structured.

And 3 appendices:

  1. Writing Backward-Compatible Code – useful for writing apps that need to work with any Ruby version.
  2. Leveraging Ruby’s Standard Library – some libraries you might not know about that can help.
  3. Ruby Worst Practices – a collection of bad examples to learn from and avoid.

The Good

Real Examples. The code examples use throughout the book were extracted from actual open source projects. This is really great because you get to see how other people are actually solving problems, rather than just theoretical and abstract examples.

Practice Code Reading Skills. Each chapter starts off with some sample code taken from an open source project, which you may not understand at first. This is a good exercise at reading other people’s code, which is essential to becoming a better programmer. Once you get a grasp of the problem, Gregory Brown then goes into more detail and explains various techniques that can be used to solve that problem.

Nice read. I enjoyed the way the book was written. Gregory Brown writes in an easy-to-understand way, with a friendly “voice” which makes you feel like he is in the trenches with you. Another thing I appreciated was that each chapter ended with a few bullet points summarizing the covered topics and offers some advice on when you might want to use some of them. (Check Tip #2 to make the most out of the examples).

The Bad

There’s not much I didn’t like about this book, only a few nitpicks really.

Lost interest when I got to Chapter 7. Although this is not the book’s fault, rather it was me that wasn’t really interested in that chapter (“Reducing Cultural Barriers”) to begin with. I just read it half way and then jumped to the next chapter which renewed my interest. (Check Tip #1 to avoid this).

Long examples with a lot of baggage. The examples presented in the book, namely the ones at the beginning of each chapter, are sometimes long and need a bit of context. I actually think this is good, but some might not like it. What it comes down to is: this is not a cookbook for copy-and-pasting solutions straight into your project. The book tries to show you the many tools Ruby gives you to solve your problems, which you then have to transpose into your project and think about it.

Extra: Reading Tips

Here are a few reading tips that will help you make the most out of the RBP Book:

  1. Read the most interesting chapters first. Each chapter is fairly self-contained so read the chapters in any order. This way you won’t rush through reading Chapter 1 just to get to Chapter 2, for example.
  2. Reread the code examples. Once you’ve finished reading a chapter, before proceeding to the next, go back and reread the initial example that got you started. Make sure you now fully understand it.
  3. Read your book next to the computer. Take your time reading each chapter and pause often to actually try out the new concepts you’ve learnt. And most importantly, play with the code, have fun!

And The Verdict

If you’re really interested in honing your Ruby coding skills, then this book is for you. It will show you how “real” Ruby code is written, what techniques you have at your disposal while tackling those hard-to-solve problems, and at the same time practice your code reading skills.

Even though the book is being open sourced, I still think you should support the hard work of a fellow programmer and buy a hardcopy. Personally, I prefer holding a book in my hand while reading, then again, I might be a bit “old-fashioned” that way. Plus, if you buy it then you’re showing O’Reilly that it’s worth open sourcing their books.

Hope you enjoy it. Happy reading!

Posted on 07 March 2010 under Programming
blog comments powered by Disqus