Seven Sandi Metz Quotes on OOD I really like

Currently, I am making my way through Sandi Metz’s 2012 book Practical Object Oriented Design in Ruby. After reading two chapters from it over the weekend, plus watching this 47-minute 2009 conference talk on Solid Object-Oriented Design given by Sandi Metz, I am finding myself in awe of her approach, that it inspired me to create this college freshman meme that was all the rage back in 2011.

This meme did not age very well

Her story-driven approach to explaining OOD concepts makes it very entertaining to see how a program starts out simple, then gets cluttered as more functionalities get added, then refactored and reorganized to save itself from entanglement and chaos.

Throughout her talks, she peppers in these great quotes and one-liners that I find very applicable/philosophical at the same time. I will list some of my favorites below.

On overall design principles…

Failure of OOD is failure of perspective, not failure of coding technique.
TDD will punish you if you don’t understand design.
Design is more the art of preserving changeability than it is the act of achieving perfection.
Anyone can arrange code to make it work right now.
In the beginning, your application was perfect. And then it changed…Dependencies are killing you. Design might save you.

On how to check if a class adheres to a single responsiblity principle…

Attempt to describe a class in one sentence. If the simplest description you can devise uses the word “and,” the class likely has more than one responsibility. If it uses the word “or,” then the class has more than one responsibility and they aren’t even very related.

On how to check if a class contains behavior that belongs somewhere else…

One way is to pretend that it’s sentient and to interrogate it. If you rephrase every one of its methods as a question, asking the question ought to make sense. For example, “Please Mr. Gear, what is your ratio?” seems perfectly reasonable, while “Please Mr. Gear, what are your gear_inches?” is on shaky ground, and “Please Mr. Gear, what is your tire (size)?” is just downright ridiculous.

Closing Thoughts

As I have lately been focusing on interview questions, whiteboarding algorithms, and keeping my skills sharp on the frameworks that I have learned, it feels nice to take a step back and see the forest from the trees with this book.

Reading this book is very much different from my usual routine of: solve a Codewars challenge until all the tests pass, refactor it to the best of my ability, see the solution and marvel at how perfect and elegant it is.

Instead, it’s great to be able to see the process of Sandi writing out code and gently evolving and refactoring it to accomodate changes. It feels much more akin to real life. I am looking forward to the next seven chapters ahead.