2 years ago
Ruby Best Practices
a little book review
Ruby Best Practices (RBP) by Gregory Brown is unlike any previous book on Ruby written yet. I really like it. This is not a book of commandments, recipes, design patterns, or style guides. Rather this is a book that is designed to help intermediate Ruby programmers learn how to think about writing and analyzing software.
If RBP had a biggest strength it would be its case-study approach of looking at real-world Ruby software as the context for best practices. It is not a theoretical or hypothetical book but very practical. One of the premises of RBP is that best practices have a context—a time and place—and aren’t just rules we slap across everything indiscriminately. It is meant to spur dialogue and provoke thought. It will help give you a new set of eyes as you read through Ruby source code (which brings up another premise of RBP—you should be learning by looking through the source code of real projects).
If RBP had a biggest weakness, it would be that it was written by one guy with help from a few others and it is limited to their observations and experience. Not everything is covered nor can it be. Somebody will complain that it is not complete but Gregory has sort of preserved himself from that sort of fault-finding by presenting this more as a “one side of the diamond” than a “here are the best practices, follow them” approach.
I think that RBP is important for the Ruby community not because it contains the solutions to everyone’s problems but more because it can serve as a great launching point for important discussions that will help us to think through the Ruby software we write and how to glean from the outstanding solutions other Rubyists smarter than ourselves have come up with.
I like the way this book is organized for the most part. The chapters are topical and focused and can be read in any order according to what is most interesting to you at the moment. There is a lot of code in this book and doesn’t make for an easy skim—you should just know that. I got the most out of this book when I had my text editor open and tried out some of the ideas as I went along.
One of my favorite O’Reilly books is Perl Best Practices by Damian Conway (go ahead and tease). I expected this book to to take a similar format—PBP is categorized into chapters and sub-divided into about 100 core principles such as “Use croak instead of die”, “Use hashes for arguments > 3”, and so on. RBP is not organized like that at all—perhaps because it would not serve Ruby developers as well… I don’t know.
It should be mentioned RBP is a Ruby 1.9 “moving forward” book and will hopefully remain relevant longer.
RBP is very rich with ideas and perspectives and examples but there are also a lot of simple takeaways that will stick with me as long as I write code in Ruby. Though it is rich and probably not a book you can master in one reading there are many nuggets and tips that will give you immediate gratification. Some of these tips seem so minor but they amount to be the things that save us tons of time (see Chapter 6 “When Things Go Wrong” on making the most of Ruby’s reflection for debugging). You should check it out, read it in your user group or dev team and discuss it. I really think we need more of these type of practical best practices books and blogs and case-studies and discussions and I am glad for the appearance of this book.
3 years ago
I’ve heard of this books fame and I have to say that every programmer should read this book. This is such a fun book to read. Even though I’ve never written any Scheme really, except on paper to work out some of the problems in the book, I see the connections to other languages I use more frequently—Javascript and Ruby, for instance.
This book teaches recursion and functional programming techniques in an effective way. It reads like Socratic dialogue and has cute cartoon elephants and food problems.
It will make you appreciate and maybe even love functional programming. Lambda-power.
Today I learned:
(define lat?
(lambda (x)
(cond
((null? x) #t)
((atom? (car x)) (lat? ( cdr x)))
(else #f))))
