Hackernoon logoThe Programming Language of Music by@rohanarthur

The Programming Language of Music

Rohan Arthur Hacker Noon profile picture

@rohanarthurRohan Arthur

TL;DR: music and software, similar approaches; if you appreciate one, then there’s a real good chance that you might appreciate the other. Also, a bit of nerd-ing about the pentatonic scale. If you know music theory, I suggest you skip this one. ☺

Music “production” is so much more than the song. Similarly, software “production” is a much larger canvas than just the code. However, the song and the code remain the vital nuclei of music and of software. The most creative part of each endeavour is somehow also the most essential.

Depending on the kind of day I’m having, I might take 15 minutes to write a fantastic song, or a week to write a mediocre one. But what makes a song or piece of code great? I submit that it is a combination of eloquence and simplicity. This applies as much to a song as it does to a piece of code.

How similar are they? Well for starters, both have two important components: theory and practice. I cannot call myself a musician if I don’t know the theory, even if I were to practice playing the violin for 5 hours a day for 10 years. Nor does my claim become any more credible if I have a PhD-level knowledge of music theory, but I don’t know how to shift from one chord to the other on the piano. Well, a safe disclaimer from me at this juncture: I am no musician. And, to round it off, I’m probably pretty average at coding too.

Yet, I find that understanding how the system works helps me to pursue either discipline with confidence and maybe also a reasonable amount of dexterity. Consider this: the instrument is the operating system and IDE, and the notes are the programming language. Then, scales and modes are the syntax.

The following paragraphs are about how I understand music theory, and if you would like to see it in action, on the guitar, I strongly recommend Marty Schwartz. He’s a real champ: it is unbelievable how patient he is in his instructional videos! Or if you really get inspired and want to shift gears to some more structured learning, I recommend Paul Gilbert. Paul is all flair and confidence. He will blow you away and convince you that you can play even the toughest solos. If you find an inclination for other instruments, I am sure YouTube will lead you to some fine teachers for these too.

Psst.. I rather like the minor pentatonic scale, and it is probably the most popular one among musicians. The secret intention of this article is to present the pentatonic scale, but before that, a bit about the basics.

The Octave

Maybe you already know that the full range of notes is calibrated as 12 ‘stops’ or ‘tones’: ranging from C — G, and then again from A — C. How is this? If you’re new to this, don’t panic. Just know that the “#” is pronounced as “sharp”. For example, “F#” is to be read as “F sharp”. So the notes are arranged as follows:

So there you have it: the music train starts at C, and then goes to 11 stations before coming back to C. This is the representation of an octave. Write these notes above on a piece of paper as you’re reading this, it will help with understanding the next couple of concepts. Or better still draw it out like this:

Why “octave”? Because there are 8 letters: C, D, E, F, G, A, B, C. These are the 8 notes or tones that make the octave, and the #’s in this case are called semi-tones. So, D is one tone higher than C. And, G# is half a tone lower than A. So those are the eleven distinct notes (and a C added at the end for completeness), and this is the most basic vocabulary of all music.

Rule 1: Remember, E and B don’t have sharps.

Remember high school physics? Each note represents a sound wave with a particular frequency, and the frequencies increase gradually as you go up the octave. That means, the frequency of D# is higher than that of D. So we say, D# is half a note higher than D. Or F is one note lower than G.

Now let’s complicate this further. Like you just met the #(sharp), you need to know his enemy the ♭(flat). The #(sharp) denotes a half-note increase, whereas the ♭(flat) denotes a half-note decrease. So if we attempt to write down all the notes as above, but this time with ♭’s instead of #’s, we get:

Rule 2: So, following from Rule 1 above, F and C don’t have flats.


A musical scale is a subset of notes from the full range of 12, played either in ascending or descending order. There are many kinds of scales, and we will see three types: the major, the minor, and of course my favourite, the pentatonic. Every scale has a root. For example, the A major scale has the root at ‘A’. The C# minor pentatonic scale has the root… you guessed right, at ‘C#’.

Perhaps we can visualise a scale as a circular doubly linked list. At least during the phase of learning a scale, it makes sense to know the sequence of notes in both the ascending and descending order. At the time of execution, when you’re playing on stage with the spotlight on you, you will obviously not be playing the notes of the scale in sequence, but knowing the structure well gives you the freedom to execute with excellence.

The Major Scale

The major scale consists of seven notes, arranged as follows.

Let us try to derive the the notes in the C major scale. 
- The root would of course be ‘C’. 
- For the second note, one step up would be, counting two half steps from C… C#… D. 
- Then for the third note, another step up would be, counting two half steps from D… D#… E
- For the 4th tone on a major scale, remember it is only a half step up. So half step up from E would be E#? 
Aha! Rule 1, E’s and B’s don’t have sharps! So the 4th note would be an F. And so on… Here’s the C major scale.

C →D →E →F →G →A →B →C

That was easy. Here is the C Major scale in action.

Let’s try one more. Say, A. 
- The root, of course, is A
- 2nd note is a full step up. That is, counting two half steps from A…A#…B
- 3rd note is again a full step up, and that is, B…C…C#
And so on… Here’s the A major scale.

A →B →C# →D →E →F# →G# →A

Hope you’re getting a hang of this. Maybe, try deriving some on your own. Perhaps, D# major and G major. You might want to take some time here because if you get this, you’ve cracked the rest of it, really.

The Minor Scale

There are several kinds of minor scales, and here we will see the ‘Natural Minor’. The natural minor scale is derived from the major. Take a happy sounding major and turn it into a sad sounding minor. Example:


To derive the minor, the root remains the same, but some small shifts to the major scale transforms it into an entirely new monster. Easy: take the happy major scale, and throw a bucket of flats at the 3rd, 6th and 7th notes to make it sad.

Deriving for the C natural minor scale: 
- you take the root as C
- A full step up from C is, as you count, C…C#…D
- A half step up from D is D# (or E♭), and so on. 
The C natural minor scale is:

C →D →E♭ →F →G →A♭ →B♭ →C

See? Just put in a flat at the 3rd, 6th and 7th positions to get the natural minor scale. This scale is not so intuitive in the language of sharps, but that would be:

C →D →D# →F →G →G# →A# →C

That’s it. Try a couple on your own, if you like (Say, the B minor and the F# minor scales). And here is a video of the C natural minor in action.

The C Natural Minor Scale

The Minor Pentatonic

This beautiful scale has only 5 notes, and therefore the name pentatonic. Technically, there are many kinds of pentatonic scales, but people usually refer to two kinds: the Major Pentatonic scale and Minor Pentatonic scale. But when the major/minor is not specified, it is pretty safe to assume minor.

I could go on all day about why the pentatonic scale is so special, but I will let Bobby McFerrin demonstrate instead.

Bobby McFerrin Demonstrates the Power of the Pentatonic Scale

The Pentatonic scale has 5 notes, derived as the positions 1, 3, 4, 5, 7 on the natural minor scale. No need to scroll up, here is the C minor scale again, but this time, the pentatonic positions have been highlighted.


Simply, the C minor pentatonic scale consists of, by picking positions 1, 3, 4, 5 and 7 from above,

C →E♭ →F →G →B♭ →C

Here is Marty Schwartz showing you how to play the A minor pentatonic on his beautiful red stratocaster.

Marty Schwartz: instructional video on the A Minor Pentatonic

Although in practice this is one of the simplest scales to learn and master, in theory, it’s simplicity and beauty can be appreciated only if the student has rigorously followed the progression from major to natural minor and only then has arrived at the minor pentatonic. Does this remind you of something from work?

I used to wonder back in school why we needed to know how to draw a circle using the dastardly mid point algorithm, when one could always just use some DrawCircle() kind of function. Well now I appreciate the advantages of academic rigour. Just last week, I spent hours debugging a really gruesome bug, and found the root cause to be some dodgy application of De Morgan’s laws deep inside an if..elseif rabbit hole.

That’s it, folks. Frankly, I’m surprised that you’ve made it this far down the article with me. But for the few who have persevered: I hope this gave you a taste of how structured and beautiful music can be, just like your structured and beautiful code.

In closing, I will let two icons demonstrate the E minor pentatonic scale: first Angus Young, then Eddie Hazel.

AC/DC — Back in Black (E Minor Pentatonic)
Funkadelic — Maggot Brain (E Minor Pentatonic)

Read next: Part 2 of the series, Debugging the C Major Scale with Dave Brubeck.


Join Hacker Noon

Create your free account to unlock your custom reading experience.