If composers were hackers
✏ 2023-04-01 ✂ 2025-10-26- Introduction
- Johann Sebastian Bach
- Wolfgang Amadeus Mozart
- Ludwig van Beethoven
- Alexander Nikolayevich Scriabin
- Closing words
Introduction
Music is my first true loveComputer games are my zeroth true love.. The first time I got my hands on an old untuned guitar, I didn’t want to put it down. I found a summer job to buy my first instrument and pay for a teacher, and since then, music has been a constant source of joy in my life. Picking a degree in computer science over a music college was a tough choice for me.
I can’t help but look at the world through the lens of my music obsession.
There are many deep similarities between music and computing,
but we won’t explore them in this article;
I will instead explore a silly and subjective question:
If my favorite composers decided to write some code, which language would they pick?
Johann Sebastian Bach
Johann Sebastian Bach is arguably the most talented and prolific musician in history. He would love the apl programming language:
- Bach’s music is terse like a well-written apl program. He achieves immense expressive power with a few well-chosen constructs.
- In his lifetime, Bach was famous primarily for his improvisation skills. apl is perfect for live coding because of its interactivity and terseness.
- Motifs and keys in Bach’s music bear deep symbolic and emotional meaning. For example, a twisted motif might mean a crucifixion and a sequence of twelve beats might depict a clock striking midnight. Bach would appreciate how apl assigns meaning to symbols.
- Bach was phenomenally prolific, cranking at least one cantata (about 20 minutes of music) per week for Sunday church services for over three years, writing over three hundred cantatas in total, and it wasn’t even his primary duty. Only a caffeinated apl wizard can match this pace.
- The Voyager Golden Record contains three compositions by Bach. If we had to prove to aliens we can compute, apl is the language to etch on a golden disk.
{(0∘, ⍪ 1∘,∘⊖)⍣⍵⍉⍪⍬}Resources
If you want to learn more about J.S. Bach:
- Listen to the Bach and the High Baroque course Audible.com offers subscribers all courses I mention in this article for free or at a meager price. by professor Robert Greenberg.
- Read Johann Sebastian Bach: The Learned Musician by Christoph Wolff.
If you want to learn more about apl:
- Read Ken Iverson’s acm Turing Award lecture Notation as a Tool of Thought. The jsoftware website hosts this and many other papers on apl.
- Read Mastering Dyalog apl by Bernard Legrand and play with the Dyalog apl Tutorial.
- Listen to the ArrayCast and APL.Show podcasts.
- Watch the Depth-first search in apl video for inspiration.
- Consider getting a physical copy of APL: An Interactive Approach book by Leonard Gilman and Allen J. Rose. The content is pretty dated, but it’s one of the most engaging books on programming I’ve read.
Wolfgang Amadeus Mozart
Mozart’s musical genius was so bright and enigmatic that mysteries and myths still surround his life.
Mozart pairs well with the Scheme programming language.
- Mozart’s music reflects the values of the age of enlightenment: it’s clear and beautifully constructed. Scheme is just as simple and elegant: An introduction to the language fits in a few pages.
- Mozart mastered all genres of his time. Scheme is a programmable programming language; it is versatile enough to be helpful in any domain. And just like opera had a special place in Mozart’s heart, programming language research sparks Scheme hackers’ joy.
(define (deriv exp var)
(cond ((number? exp) 0)
((variable? exp)
(if (same-variable? exp var) 1 0))
((sum? exp)
(make-sum (deriv (addend exp) var)
(deriv (augend exp) var)))
((product? exp)
(make-sum
(make-product (multiplier exp)
(deriv (multiplicand exp) var))
(make-product (deriv (multiplier exp) var)
(multiplicand exp))))
(else
(error "unknown expression type -- DERIV" exp))))
Resources
If you want to learn more about Mozart:
- Listen to the Great Masters: Mozart—His Life and Music course by professor Robert Greenberg.
- Read Mozart: A Life by Maynard Solomon.
If you want to learn more about Scheme:
- Read The Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman. It’s worth reading even if you don’t care about Scheme.
- Read The Little Schemer and related books: The Reasoned Schemer, The Little Typer, The Little Prover, and The Little Learner.
Ludwig van Beethoven
Beethoven is the most influential composer in history; he single-handedly changed the direction of western music and the role of an artist in society.
One of the few languages worthy of Beethoven would be Haskell:
-
Beethoven constructed most of his music from tiny motifs and rhythms, many of which seem dull in isolation.
Good Haskell code thrives on composition of small, often trivial functions like
idandfix. - Beethoven was constantly evolving his style, pushing the boundary of the art. He reinvented himself twice during his career, turning his suffering into fuel for breakthroughs. Similarly, the Haskell ecosystem constantly evolves, turning pain points into novel ways to write and think about software. For example, issues with lazy input/output led to the invention of iteratees, and the inconvenience of nested record updates led to lenses and bidirectional programming.
- Beethoven turned my musical world upside down: I caught a piano bug after hearing The Tempest sonata finale. Haskell had a matching influence on my professional life, forever changing how I think about computing.
data KMP a = KMP { done :: Bool, next :: (a -> KMP a) }
makeTable :: Eq a => [a] -> KMP a
makeTable xs = table
where table = makeTable' xs (const table)
makeTable' [] failure = KMP True failure
makeTable' (x:xs) failure = KMP False test
where test c = if c == x then success else failure c
success = makeTable' xs (next (failure x))
isSublistOf :: Eq a => [a] -> [a] -> Bool
isSublistOf as bs = match (makeTable as) bs
where match table [] = done table
match table (b:bs) = done table || match (next table b) bs
Resources
If you want to learn more about Beethoven:
- Listen to the Great Masters: Beethoven—His Life and Music course by professor Robert Greenberg.
- Read Beethoven by Maynard Solomon.
- Consider watching the Immortal Beloved movie. It’s inspiring despite its many factual mistakes.
If you want to learn more about Haskell:
- Read Learn You a Haskell for Great Good! by Miran Lipovača, an engaging illustrated introduction to Haskell.
- Read The Haskell School of Music by Paul Hudak and Donya Quick; it demonstrates the best sides of Haskell by building a library for music generation.
- Check out the Haskell documentation page for more great pointers.
Alexander Nikolayevich Scriabin
Scriabin is a relatively obscure Russian composer who wrote deeply expressive, emotional, metaphysical music. He also had the most stylish mustache among all composers. He would love Scala:
- Scriabin dreamed of fusing arts into a synthetic form he called Mysterium. Similarly, Scala aims to be extensible enough to embrace all programming styles and paradigms, including functional, object-oriented, and actor-based.
- Scriabin’s music feels profound and unfathomable, like the night sky. Scala inspires the same awe: I admire its structure and elegance, even as its complexity makes my head spin.
scalaz library documentation.
implicit val option: Traverse[Option] with MonadPlus[Option] =
new Traverse[Option] with MonadPlus[Option] {
def point[A](a: => A) = Some(a)
def bind[A, B](fa: Option[A])(f: A => Option[B]): Option[B] = fa flatMap f
override def map[A, B](fa: Option[A])(f: A => B): Option[B] = fa map f
def traverseImpl[F[_], A, B](fa: Option[A])(f: A => F[B])(implicit F: Applicative[F]) =
fa map (a => F.map(f(a))(Some(_): Option[B])) getOrElse F.point(None)
def empty[A]: Option[A] = None
def plus[A](a: Option[A], b: => Option[A]) = a orElse b
def foldR[A, B](fa: Option[A], z: B)(f: (A) => (=> B) => B): B = fa match {
case Some(a) => f(a)(z)
case None => z
}
}
Resources
If you want to learn more about Scriabin:
- Read The Alexander Scriabin Companion: History, Performance, and Lore by Lincoln Ballard and Matthew Bengtson.
- Read Scriabin, a Biography by Faubion Bowers.
If you want to learn more about Scala:
- Read Programming in Scala by Martin Odersky et al., and Functional Programming in Scala by Rúnar Bjarnason and Paul Chiusano.
Closing words
There are many more great composers and excellent programming languages. Matching these is left as an exercise for the readerBonus points for finding a good match for php..
I like how hosts of the My Favorite Theorem podcast ask their guests to pair theorems with more tangible things and activities, such as pizza and rock climbing. Try it with the things or people you like, it’s fun! Enjoy your favorite things!
Similar articles
- Good names form Galois connections
- Debug like Feynman, test like Faraday
- Static types are for perfectionists