Music and Coding: Two Inimitable Planets Orbiting the Same Sun
I’ve heard it said a number of times: “Coding is a lot like music.” As a musician and web developer, I can attest to that statement’s falseness and it’s intrinsic accuracy. Coding requires a laser-sharp focus and tireless work ethic, items not necessarily required at a jam session, for instance, depending whom you ask. Music, and art in general, is often about what you can do, not what you can’t do; proficiency in all areas, or even just at a base level, does not automatically dictate success. And yet, musicians are drawn to coding. I’m aware of four professional musicians at the Flatiron School at the time of this writing. And the similarities that do exist are striking. Perhaps it has something to do with unwavering commitment-you’ll need that for either discipline-and the idea that you’re building something. Is building a song verse by verse, chorus by chorus, any different from writing the code, line by line, that will amount to a shiny, glimmering new app? Below are three ways in which music is eerily similar to coding.
Methods are a lot like scales
All methods have a beginning-think “class” or “def”-and they all have an end: “end.” This will remind even the most elementary of music students of a scale. The scalar concept-a collection of notes that correspond to a key or arrangement of chords-has a beginning note, known as the tonic, and eight tones later the same note, up an octave, concludes the scale. This is how scales begin and end, generally speaking. And though a method will never end with “def,” there is a beauty to finishing how you started, if just in a slightly altered way. Here, I’m also reminded of the map method, which iterates through an array, changing each item as it goes. This is reminiscent of the musical construct modulation, which can take all of the notes in a scale and move them up or down. In fact, a scale is merely an array!

Pair Programming is just like being in a band
Pair Programming, which matches a pair of coders in pursuit of a single goal, is almost indistinguishable from being in a band. While one coder drives, the other navigates, a relationship close to that of the soloist and supporting musicians in jazz. While the navigator throws out ideas, directions, and lines of code, the driver is there to take that information and steer the ship. This is not unlike when a saxophonist is given the floor to improvise over a cushion of bass, drums, and piano. The sax player, or navigator, tosses out lines and motifs for the rhythm section, or driver, to pick up and illustrate. It’s an incredible dynamic.

Improvising, and flexibility, are central to both worlds
From jazz to rock to funk to pop, improv is a tenet you won’t go long without encountering. Some genres, like jazz, are seemingly built around the notion, but even the most straightforward radio hit might have a solo or vocal ad-lib that nearly makes the song. Similarly, no two coders will write a method in exactly the same way. No two programmers will solve the same problem with an identical approach. And both coders and musicians need to be flexible. Getting an error message? Hearing a note or notes land gracelessly out of key? How will we resolve these problems? What’s the most efficient fix?
