Abstractions in Music

I’ve been trying to find a way to explain abstractions in a way that prevents the dreaded “over abstraction”. Those pesky abstractions that cause more work than they intended to prevent. You know, the one that makes you have 15 files open to find where a piece of text is inserted into the database. Before you know it the friendly janitor is vacuuming around you after you finally found the end of the indirection just to say “hello”.

I’ve written these before. It was painfully obvious when I had to explain to my coworker how the PTR record was generated while rewriting a part of DigitalOcean’s DNS. He commented about 5 minutes in “there’s so much indirection here”. He wasn’t wrong. It should be simple to take an IP and create it as a PTR in a simple RESTful service. But here we were, 15 files scattered across Sublime Text. I had messed up. Not only had I created technical debt, I created a super massive brainhole that would cause the engineers after me to likely lose the willpower to work on that system. Finding great engineers is tough already, but finding ones that dive in and still manage to smile is especially hard when they have brainholes to work on.

The wrong abstraction is more impacting than “this system is harder to change now”. Sometimes it creates a concrete wall preventing new engineers from shipping new products. Which affects moral. Which means engineers leave. Engineers will leave an organization if their code doesn’t ship regularly. Period.

Also, don’t think improper abstractions are just limited to software development. Everything is an abstraction. A steering wheel on a car is an abstraction. You’re not responsible for know how a front differential works as the driver. Your job is to know how the steering wheel affects the direction of the car and nothing else.

The Perfect Abstraction

An orchestra is a group of musicians playing string, brass, percussion, and woodwind instruments. An orchestra as a whole makes use of abstractions that have been in development for centuries. Let’s look at some of the finer details of the abstractions in music that make it such a fine tuned (pun intended) process.

The Instruments

Within an orchestra you have the masters of their instruments. But why even have dozens of different instruments? It’s all about the features of the instrument. The sounds they make, the emotions they invoke, and the impact they deliver to song in mind.

Instruments themselves are individual abstractions. Take a trumpet for example. A trumpet has a distinct sound that can play all of the notes known using just 3 keys and a brass player’s lips. But then there’s an instrument called the cornet. A cornet is almost identical in a lot of ways. It has 3 keys. It is a brass instrument. Hell, it even is in the same key as a trumpet. So why have both?

They sound different. Bending the will of the trumpet to sound like a cornet would be a penalty flag if you follow the SOLID principles. Specifically, the “S” (Single Responsibility Protocol). Cornets and trumpets are used in different styles of music, at the discretion of the composer. Pretty soon that Trumpet has a 4th key on it you press to make it sound like a Cornet. But now we want to be able to make it pitch bend easily (Think: Trombone) so we add a large slide with a handle on it next to the keys. You get the point.

So what would an over abstraction of an instrument be? In my head there’s a possibility every instrument played one note and nothing else. Imagine a piano with 1 key and it plays a C every time you press it. Sure, it now has a single responsibility, but that responsibility is dumb and degrading. So the responsibility is increased but not widened. It still fulfills the need for a piano sound, but without the need for 52 single keyed pianos.

The Musicians

Imagine also if an orchestra member was told to play a single note on beat 1 and another member to play a different note on beat 2. Sure, both have a very specific responsibility, but is it really needed? Isn’t it less cognitive overhead for the conductor if both of those notes were just played by the same musician?

Imagine if a musical piece had 36 different notes per instrument but each member was only allowed to play 1 of those pitches. Your orchestra would have probably 600 members in it to be able to play just 1 piece of music!

The Relationship To Software

I’ve made the mistake of making an object for every mind numbingly easy thing to do. Thinking back to my PTR debacle, I had an object for every step of the process of transforming a Droplet’s IP into the DNS REST service. I had the 600 member orchestra to play my one song. It was hard to reason about, nobody wanted to work on it, and ultimately it didn’t improve the longevity of the feature anymore than if I used 3 really well defined objects to do the work.

Make your objects work not only for your software but for your developers. Don’t make your peers read software and try to learn where every note of the orchestra that is software is played.