Music and code

Lucy Woodhead
4 min readDec 3, 2020

I’m a music graduate turned programmer, and although to some people the two disciplines are very different, I would say there is more in common than you think!

Indeed, when I first told people I was going to retrain to be a programmer, I was met with responses such as:

“One is creative and one is really maths focused”

“They are only things you can learn at a young age”

“How on earth are music and coding linked?”

As a result, I’ve done some thinking over the years and drawn together quite a few parallels that exist.

Humans as compilers

When a musician sits to play and they are reading from sheet music/tabs, they will sit and scan the music — top to bottom — and almost ‘hoist’ what’s coming up in the piece. They will read the markings, take in the time signature, and look out for any repeats or ornaments. When we run code, a similar process happens where the compiler scans all the functions and reads instructions (loops, booleans, iterations).

Both disciplines have users

There are a couple of things in life where we refer to the receiver as a ‘user’, and that includes people executing actions on apps/devices, but also infers listeners of music. At concerts, we see crowds come together and react in some way or feel some emotion to what they are hearing. With apps, we see people using interfaces together/solo and evoking reactions or emotions.

People listening at a concert
Users/recipients of software

Both are forms of self expression and creativity

If you ask me to write a function that iterates over an array of numbers and adds them, there are a few ways I might present that back to you.
I could write a for loop and add to a tally, or use a reduce function. I could even write a recursive function! In a similar manner, if you ask me to play a phrase on the piano I could play it in a number of ways. I might add emphasis on the beat, increase the volume towards the end, or use pedals to create an effect.

Components are everywhere!

When creating an application it’s common to have components or functions that are reused in several places. In music, you would have the same! Motifs, phrases, and entire sections crop up multiple times, and each iteration may be nuanced in some way. If we think of the symbols used, we can understand how the meaning is essentially the same.

Example: In Grande valse brillante, Op.18 (Frédéric Chopin), we can see that after the first section is played, the performer should return to the start for another iteration. The second time, they will play a different ending to the phrase.

Below, this function will signal the same intention as the music above. Print ‘Play again’ if it’s the first iteration, but print ‘Last time’ if it’s the second.

for (let counter = 1; counter <= 2; counter++) {
if (counter < 2) {
console.log('Play again');
} else if (counter === 2) {
console.log('Last time!');
}
}

They are activities that can be done solo or as part of a group

When you complete a coding task you can do it on your own, in a pair (pair programming) or as a group (mob programming). Usually you are building a feature, something that will then become part of something bigger and makes up an entire application. In music, you can also play or compose on your own as a soloist, perhaps in a pair (duo), or in a group (ensemble). Once again, we see similarities in the disciplines and how achieving an end performance/goal can often begin with these setups.

Open source and the community

If you are in a band you will likely contribute something to a song, whether that be some lyrics, a beat, or a riff. More often than not you will have contributed a part that has been accepted by the other musicians and then implemented into the song. When coders contribute to open source projects, they will add a feature, a function, or some new mechanism that is also approved by peers and is then implemented into the code.

With all this in mind, it can be agreed that music and programming have some similarities to explore and I know that for myself, upon reflection, that being a musician first really helped me when I then pivoted into coding.

--

--