Raging with the Machine

Part 1 of the Arts and Programming Series

POP QUIZ:

What do you call writing in a language made up of a set of letters and characters that when strung together operate to perform specific tasks and functions? If you guessed programming, you’d be correct. However, if you guessed music composition, you’d also be correct! Now pat yourself on the back.

You said this was a quick and easy guide. Tell me how in three easy comparisons.

I would be happy to do so. In this guide, we’re going to look at two different pieces of music while using Ruby code. We don’t need an example for the first comparison (as it can be used with any piece of music), but we will use Train’s “Drops of Jupiter” for the second, and George Gershwin’s “An American in Paris” for the third.

1. Object-Relational Mapping:

What is a piece of music other than a series of several different objects with One-to-Many and Many-to-Many relationships? Composers write many pieces (Has Many Relationship). Instruments can be found in countless pieces (Has Many Relationship). But, each piece only has one composer (or composer team) and only one set of instruments (Belongs To Relationship). There is your connection. So, essentially, your objects may look something like:

class Composer
attr_reader :first_name, :last_name, :full_name

def initialize(first_name: first_name, last_name: last_name)
@first_name = first_name
@last_name = last_name
@full_name = "#{first_name} {last_name}
end
...
end
class Piece
attr_reader :composer
attr_accessor :instruments
def initialize(composer)
@composer = composer
@instruments = []
end
def add_instruments(instrument)
@instruments << instrument
end
...
end
class Instrument
attr_reader :instrument
def initialize(instrument)
@instrument = instrument
end
...
end
etc...

2. Class Inheritance and Song Form.

First off, what is Song Form? Song Form is exactly what it sounds like; the structure, or form of a song. Let’s take a look at “Drops of Jupiter” by Train. The form of this song is as follows:

Verse,
Chorus,
Verse,
Chorus,
Bridge,
Chorus
Outro
class Verse
class Chorus
class Bridge
class Outro
class SecondVerse < Verse
def second_verse_drum_rhythm(drums)
@second_verse_drums = drums
end
def second_verse_lyrics(lyrics)
lyrics
end
...
end
class Outro < Verse
def outro_lyrics(lyrics)
lyrics
end

def final_chord
@final_chord
end
...
end

3. Methods and Instrumental Functions.

One of my personal favorite aspects of Gershwin’s “An American in Paris” is his ability to recreate what he heard and saw during his time there. Luckily for me, that very aspect is the perfect example of a Method. Take a quick look at this excerpt:

class Piece def paris_at_night
sultry_trumpets = Instrument.all.select |instrument|
instrument.name == "trumpet"
end
...
end
end

There you have it.

Once again, this a very basic intro into the parallels between composition/songwriting and being a programmer. With practically every aspect of the two fields, you can make comparisons. Who knows? Maybe the next great programmers will be hybrids of Leonard Bernstein and Matz or George Harrison and Brendan Eich. Now, do yourself a favor, and go be the best rockstar programmer you can be.

Coffee lover, Full Stack Developer, Flatiron School Alum, former professional Singer/Actor/Dancer/Musician.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store