Cl-Obs. Clobs. clobs.

Collaborating objects in Ruby (or as I call them in my head, Col-Obs, pronounced “clobs” because of what they do to my brain) are the weeds. Except they’re not the nice, neat weeds that you can slide through like a Velociraptor in the tall grass.

Velociraptor killing people Lost World

They’re tangled together, itchy weeds that trip you up with their selves and capital letters and commercial @. That’s the kind of weeds Col-obs are. And that’s the weeds we need them to be.

garden gnome in weeds

We need objects to have relationships with each other, to act and be acted upon simultaneously. That’s how the world works–we change the world by interacting with it, and the world changes us as we do so (deep, amiright?). But unlike some of the simple relationships that happen automatically (such as an artist writing a song and having that song belong to that artist), the relationships between classes and their instances proved challenging for me to understand. I was in the weeds. And unfortunately the weeds were in me.

Weeds covering cyclist

Now I still haven’t 100% detangled the weeds (there’s no real untangling of them–you just master them), but I’m working on it. The more I create classes, the more I have to manipulate them and the more experience I gain wrapping them around my brain rather than vice versa. I require time, experience, and, well, play for my brain to get comfortable with this sort of construction and manipulation.

In the meantime, the best way for me to work through these Col-Lob-bering issues (see how I did that?) is to create copious notes, explaining what exactly I need the method to do and how I need it to interact with other classes and their respective methods. It’s almost a form of storytelling, this translation of code into full-on English sentences; for example, classes such as Artist, Song, and Genre get spelled out with words first. We say to ourselves: an artist creates a song that is an example of a genre. That song then becomes a part of her repertoire, and that genre a part of the musical world she inhabits. It’s not a riveting story, but it explains the relationships I need it to. In short, it keeps the weeds tangled but understandable in my brain.

So although the stories are simple for the moment–full of music libraries and MP3 importers–the more I work with them, the more complicated and interesting I believe the narratives will become. Until maybe someday, when I look at the terminal, filled to the brim with classes and objects, methods and variables, I’ll see the tiny rages of Oberon and Titiana storm across my environment, and slyly smile as Queen Mab animates a Fairy class’s dreams.

Richard Dadd Fairy Feller's Master Stroke

← Previous Post Next Post →