# Raging with the Machine

## 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 ...endclass Piece attr_reader :composer attr_accessor :instruments def initialize(composer)  @composer = composer  @instruments = [] end def add_instruments(instrument)  @instruments << instrument end ...endclass Instrument attr_reader :instrument def initialize(instrument)  @instrument = instrument end ...endetc...`

## 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,ChorusOutro`
`class Verseclass Chorusclass Bridgeclass 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  ... endend`

# 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.

## More from Brian DiRito

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

## You’re Either Getting Better or You’re Getting Worse

Get the Medium app