Object-Oriented Design in Ruby

Ruby is a beautiful programming language and a fantastic language for beginners.  It's clear, simple syntax makes it accessible, and it's amazing how much you can get done in a few short, simple lines of code.  Combine Ruby with the Rails framework, and newcomers can hit the ground running fast.  This speed is both a wonderful and a terrible thing.

As a coding newbie, learning Ruby on Rails was like discovering I had a superpower.  Oh, the power!!!  Learning to code felt audacious and intimidating at the beginning, but here I was, really doing it.  I was building something that could live on the Internet and do cool stuff.  It was - and still is - a heady feeling.

The danger in Ruby's simplicity and Rails' power is that it can lull us into a state of complacency.  It's so easy to get stuff done with these tools, but the obvious way - expecially the obvious way to a novice programmer - isn't always the best or the most sustainable way.

Having a superpower is great, but every superhero has to learn how to wield his/her powers effectively to experience their full potential.  After exploring Ruby and Ruby on Rails for a year, I was ready to level up.

Enter Sandi Metz' book: Practical Object-Oriented Design in Ruby.

From the first line of the introduction, Metz feels like an old friend.  Her voice is engaging and encouraging as she describes what draws us to the practice of writing code.  "Those of us whose work is to write software are incredibly lucky.  Building software is a guiltless pleasure because we get to use our creative energy to get things done.  We have arranged our lives to have it both ways; we can enjoy the pure act of writing code in sure knowledge that the code we write has use."

The subsequent chapters cover topics such as single responsiblity, loose coupling, using classes and inheritance effectively, creating good interfaces, and writing effective tests.  The tone stays friendly, and the examples are clear and easy to follow as Metz demonstrates good, better, and best ways to structure code.  Along the way, she demonstrates how to think about code design and make intentional choices based on current knowledge that will be easy to live with and adapt in the future.

It's a pretty quick read.  I'm on chapter 7 right now, and I'm looking forward to reading the rest.  I'm also starting on a new epic for an open source project, and I find myself thinking hard about my choices as I start out.  Applying the ideas in the book will take time and practice, and I have a feeling I'll come back to it many times.  It feels good to grow, though, and to know that my code will be better and more useful for the effort.

Back to Posts