Refactor Songs and Code

I love to write code. It’s the only activity I’ve found that gives me the same buzz as writing a song. Here are some thoughts on similarities between writing code and writing a song.

Generally, the word “dry” refers to something boring or uninteresting. In the programming world, DRY stands for “Don’t Repeat Yourself.” If we have a bit of code that we’re going to reuse then we’d refactor it into a structure/module like a function or a method.

Songs are modular too. They can be approached as sections of reusable chords and lyrics. We reuse chord structures and repeat chorus lyrics all the time.

A tightly written, well crafted song is very concise. Part of this is for airplay and not boring the listener. There is an idiom in the songwriting world- “Don’t bore us, get to the chorus.” The quicker you can get to the hook (generally the chorus) the better. A tightly written, interesting song doesn’t meander either musically or lyrically. There is purpose. Sometimes I’ll go back and revisit an older song of mine and find ways to edit, refactor and make it better.

In the programming world we refactor all the time. We’ll try to condense multiple lines of code into fewer lines. We can encapsulate code into reusable functions and methods. Or, specifically in Ruby, I frequently use ternary operators to DRY up my code where appropriate.