Publisher: Addison-WesleyPages: 448ISBN: 978-0321584106Aimed at: Anyone wanting to be a good programmer Rating: 5Pros: A great guide to good styleCons: Sometimes a bit too enthusiasticReviewed by: Mike James

This book will make you a better programmer. Read on to find out how and why.

Author: Russ OlsenPublisher: Addison-Wesley, 2011

Pages: 448ISBN: 978-0321584106Aimed at: Anyone wanting to be a good programmer Rating: 5Pros: A great guide to good styleCons: Sometimes a bit too enthusiasticReviewed by: Mike James

This is a great book and even if you don't use Ruby it is a book well worth reading. It does major on the way that you should use Ruby and how to write Ruby in a way that is true to the language, but it has so much to say about programming in general that it is worth reading for non-Ruby programmers. It is would also be an eye-opener to compare the way your favourite language stacks up to Ruby as explained in this book.

Chapter 1 starts off the quest to write honest Ruby with "Write Code that Looks Like Ruby". The basic idea is that clarity is all. A program should shout its intent. This chapter takes us through some obvious stuff but it does it in an engaging way that makes the points clearly and persuasively. I didn't agree with all of the points, but then you don't have to. As long as you understand the reasoning and try to make your code clear you can pick your own idioms.

Chapter 2 continues this argument with a look at control structures and a topic that I think is important - use positive logic. As the author points out it is the difference between

"It is not true that Ruby is like Java"

and

"Ruby is different than Java".

There is also the problem of taking the not of an and or an or which is more difficult than you might think as not(A and B) is (not A) or (not B). This problem isn't discussed.

From these very general opening chapters the book moves into increasingly more specific areas of Ruby. Chapter 3 looks at smart collections, Chapter 4 at smart strings, Chapter 5 regular expressions and Chapter 6 deals with the mysterious topic of symbols. Then we move on to more general topics. Chapter 7 titled - Treat everything like an Object - because everything is. Chapter 8 on dynamic typing and chapter 9 on specs and test.

Part II of the book is on larger architectural issues - Classes, Modules and Blocks - but don't let my description put you off. This part of the book explains how to make use of the basic organizational principles for code. Chapter 10 explains what makes a good class. Chapter 11 deals with operators and defining your own. Chapter 12 is on class equality, 13 is on the singleton pattern, 14 on instance variables, 15 on modules as namespaces, 16 on modules as Mixins. Chapter 17 looks at the use of Blocks in iteration, Chapter 18 is a collection of uses for blocks and Chapter 19 is about saving blocks for deferred execution.

Part III is about metaprogramming - something Ruby is very good at. This outlines the usual techniques for modifying and extending the Ruby language - hooks, method_missing, monkey patching, self modifying classes and classes that modify their subclasses.

Part IV is about putting it all together and it majors on creating Domain Specific Languages - again something Ruby is very good at. There are two chapters on DSLs, a chapter on packaging your code as a Gem and a final one on the different Rubys.

This is a really good book and at the end of it you can't help but write better Ruby and probably better whatever other languages you use now or in the future. In this sense it will make you a better programmer.