- Author
- Luke Haas, RunJS
- Published
- 17 August 2026
- Kind
- Company blog post, with runnable code
- Original
- runjs.app/blog/music-theory-for-programmers
- Subject
- Consonance and tuning
- Themes
- Getting good, What the senses do
What it is
Luke Haas explains music theory from first principles, using runnable JavaScript. It starts with sound as numbers, then builds up to chords and progressions. It appears on the blog of RunJS, a JavaScript playground.
What it says
- Simple frequency ratios sound good, the post argues, through shared harmonics and little beating.
- Twelve pure fifths overshoot seven octaves by about 23 cents, the Pythagorean comma.
- That gap can't close, because a power of three never equals a power of two.
- Every tuning is therefore a compromise, and equal temperament spreads the error evenly.
- A short brute-force search shows why twelve divisions work well.
- Modes are one step pattern rotated, so major and minor are rotations of each other.
What evidence it gives
The mathematics is checkable, and readers can run every example. Its claims about why things sound good are explanations, not experiments.
Interests and limits
It is a tutorial from a company selling a JavaScript tool. Musicians in the discussion dispute it as music theory. See the Hacker News thread for that pushback.
Connections
These links are this wiki's own reading, not claims the sources make.
- Alternate Clock Designs & Time Systems. Both ask why a cycle has the divisions it has. The day's are inherited, de Chardon says. Haas shows the octave's twelve are a compromise. A tuning is a clock for the octave.