Like A Girl

Pushing the conversation on gender equality.

Code Like A Girl

Object-Oriented Design in Ruby

I came down with a sort of flu-like situation early last week, and so have been a bit quiet on the posting front over the last few days. I guess it’s not entirely surprising, given how hard we’ve been pushing the last few months, and how poorly I’ve been handling self-care. Guess my body finally caught up with me…

Being sick the past week has been extremely frustrating and stressful as I know I have some critical deadlines coming up. I’ve tried to power through and get as much work done as possible, but my enormous fatigue coupled with the brain fog from the sickness has made me not nearly as productive and efficient as I’d like to be. Given that we’re in the last stretch before graduation and demo day, the timing wasn’t exactly ideal, but sometimes the body will force you to stop and take a step back and rest — whether you like it or not!

My Sick Day/s Companion

After communicating with my instructor, Michael, how stressful it’s been to feel like I’m falling behind and not producing enough code during this key time, he recommended me some weekend reading for when my brain isn’t alert or nimble enough to code but for when I still want to be productive and subject-focused. The book he lent me to read is ‘Practical Object-Oriented Design in Ruby’ by Sandi Metz.

This book in particular is one I’ve had recommended to me by a number of people over the last couple of months, and upon reading the first few chapters this weekend, I can see why. It’s cleanly written in a friendly, accessible way that provides plenty of real-world, non-technical examples to help the reader grasp concepts that — in other contexts — can feel very wonky and elusive.

As the author states in the introduction, the book is written to be a “programmer’s story about how to write code” — as opposed to a highly technical “academic tome”. While certainly comprehensive, it’s also organized in a way that allows the reader to come and go as is useful to them and makes a point to create a lot of space for conceptual overview and explanation around the thinking behind the OOD approach. This is particularly helpful to a newbie, such as myself, as it takes the code outside the realm of rote syntactical memorization and into a more whole-picture/thinking-based approach.

The initial chapter presented an overview of Object-Oriented Design and included topic headers, such as: “In Praise of Design”, “The Problem Design Solves”, “Design Patterns”, “When to Design”, and “Design Principles” — in addition to several others.

Many languages — including Python, Java, PHP, C#, and C++ — use many Object-Oriented Design Principles, which are often summed up using the S.O.L.I.D. acronym. S.O.L.I.D. represents principles of varying degrees of complexity, which can be summed up as the following:

  • S(ingle-responsibility principle): a class should have only one job
  • O(pen-closed principle): classes should be easily extendable without needing to make modifications to existing functionality
  • L(iskov substitution principle): each subclass should be paired with the appropriate parent class
  • I(nterface segregation principle): clients should never need to depend on methods that they do not use
  • D(ependency inversion principle): both high- and low-level modules must depend on abstractions (methods, which are declared but don’t contain implementation)

Some of these principles make more sense to me than others, and I’m looking forward to working further into Practical OO Design to hear how Metz breaks each down into more easily-digestible components.

Resting up for the duration of the weekend, so I can hopefully head back to class running close to 100% tomorrow morning. Happy Sunday, all.

Song of the Day: “Spiral” by Wye Oak