DEV Community

Unstable Entity
Unstable Entity

Posted on

Music Theory for Developers: Why Scales Are Just Arrays

I'm a developer who plays guitar. One day I realized that music theory maps perfectly to programming concepts. If you code and want to learn theory, this is for you.

Scales = Arrays

A C major scale is just an array:

const cMajor = ['C', 'D', 'E', 'F', 'G', 'A', 'B'];
Enter fullscreen mode Exit fullscreen mode

The formula (in semitones): [2, 2, 1, 2, 2, 2, 1] — whole, whole, half, whole, whole, whole, half.

Apply that same formula starting from any note and you get a major scale in that key. It's a function:

function majorScale(root) {
  const notes = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'];
  const pattern = [0, 2, 4, 5, 7, 9, 11]; // semitone offsets
  const rootIdx = notes.indexOf(root);
  return pattern.map(p => notes[(rootIdx + p) % 12]);
}
Enter fullscreen mode Exit fullscreen mode

Chords = Slicing Arrays

A chord is just specific elements from the scale array:

function majorChord(scale) {
  return [scale[0], scale[2], scale[4]]; // 1st, 3rd, 5th
}
// C major scale → C, E, G (C major chord)
Enter fullscreen mode Exit fullscreen mode

Minor chord? Flatten the 3rd by one semitone:

function minorChord(scale) {
  return [scale[0], flatten(scale[2]), scale[4]];
}
// C → C, Eb, G (C minor chord)
Enter fullscreen mode Exit fullscreen mode

Chord Progressions = Sequences

The famous I-V-vi-IV pop progression? Just array indices:

function progression(scale, pattern) {
  return pattern.map(i => buildChord(scale, i));
}
// In C: progression(cMajor, [0, 4, 5, 3])
// → C major, G major, A minor, F major
Enter fullscreen mode Exit fullscreen mode

The "vi" is minor because of the natural intervals in the scale. The formula tells you which chords are major, minor, or diminished:

I   ii   iii  IV   V    vi   vii°
Maj min  min  Maj  Maj  min  dim
Enter fullscreen mode Exit fullscreen mode

This is just a lookup table. No mysticism required.

Keys = Namespaces

Changing key is like changing a namespace. All the relationships stay the same, just the starting point moves. If you know a song in C, transposing to G means applying an offset of +7 semitones to every note.

function transpose(chord, semitones) {
  return chord.map(note => (note + semitones) % 12);
}
Enter fullscreen mode Exit fullscreen mode

Why This Matters

Once you see music theory as data structures and algorithms, it clicks. There's no magic — just patterns, intervals, and relationships.

If you want to see these patterns in action, try looking at chord progressions across different songs in the same key. ChordRoom lets you browse by genre and decade — you can literally see how the same I-V-vi-IV shows up everywhere from 60s folk to 2020s pop.

Further Reading

  • Hooktheory — Interactive music theory
  • musictheory.net — Free lessons
  • 12tone (YouTube) — Great music analysis

What other domains do you think map well to programming concepts? I've been thinking about cooking as pipeline architecture...

Top comments (0)