/ Shareef Jackson / 3 am Tue, Jun 9 2015
  • Submit
  • About Us
  • Contact Us
  • Advertise here
  • Forums
  • How hip hop can teach you to code

    How hip hop can teach you to code

    The artist may change, but the template remains the same

    Being the DJ's son has its perks. My dad always spun old and new school classics for my brother and I, so our music vocabulary was more advanced than our ages. I could recite verses from songs that came out shortly after my birth year of 1980. During times of weakness, I would often seek refuge in the massive boxes of vinyl that my dad had in our unfinished basement.

    One thing I love about early hip hop is that while the artists may change, the structure stays the same. There's always a beat, some verses, and a chorus. There are variations on this, of course, but the structure of a hip hop song is something I internalized from childhood. It gave me a sense of comfort whenever I heard a new song, and added to the element of surprise when an artist could still be creative within the confines of that structure.

    During the late 80s to the early 90s, my favorite period of hip hop, there were plenty of artists innovating against traditional strutures. Rakim helped transition hip hop from the Run-DMC era, and established the sound of a modern MC. But there were other, weirder acts—Kool Keith and Ced Gee of Ultramagnetic MCs introduced an off-beat rap style that didn’t seem like it should work, but it did! Public Enemy combined Chuck D’s forceful delivery with Flavor Flav’s nonsense. Das EFX threw in all kinds of stutters and -iggity’s to the end of their rhymes. And the Kool Genius of Rap stuffed multiple instances of rhyming words in places that no one else could, a tactic that was later picked up by Big Pun and Eminem.

    Despite all of that, the template stays the same: beats, verses, and choruses. The only thing that changed was how the beats were produced, the delivery and rhyme schemes within the verses, and the catchiness of the chorus. I used to write my favorite rhymes in a notebook so I could memorize them. Pretty soon, I started writing my own rhymes in my black and white composition book. I would take a blank sheet of paper and write out a template. I’d split the page into four sections, and title each section as below:

    Verse 1

    Chorus

    Verse 2

    Verse 3

    I only had one section for the chorus, because I knew it would be repeated after verse 2 and 3. “Why put three different sections for the chorus if it’s the same each time?” I thought. “I can just place it once, and then reference it at the end of the second and third verse”. Most importantly, I thought “If I ever need to change the chorus, I only need to change it in one place”.

    This is when I was a pre-teen. I didn’t own a computer until I got to college, but I was already learning the basic structure behind putting together a program.

    shareefj

    When I became a code monkey in my college programming courses, I was able to use this to my advantage: The artist may change, by the structure stays the same. I would write out my programs the same way I wrote out my rhymes—start with the template,then fill in the details. Here is my old notebook, but written in terms of programming functions, which ends in parentheses():

    Verse(1);

    Chorus();

    Verse(2);

    Chorus();

    Verse(3);

    Chorus();

    There are only a few small differences between this code and my notebook from the early 90s. There is a section for each verse—Verse(1), Verse(2), Verse(3)—and a section for the chorus. The actual contents of each verse and chorus are defined later in the program.

    For example, le's look at the Chorus function.

    Chorus() {

    “ ………… Chorus text ………… “

    }

    Pretty simple, right? Every time I call the Chorus() function, it returns the text for the chorus. Just like in my old notebook, the actual text of the chorus is only stored in one place: this function. Even though I call the Chorus() function three times in the main song template, I only have to make changes in one place if I want to update the text. Go programming!

    The Verse function is a little more complicated, because this function is used to represent all three verses. Remember that number inside of parentheses - Verse(1), Verse(2), Verse(3)? That number determines which verse is returned. Let’s look inside of the function:

    Verse (int VerseNumber) {

    if VerseNumber = 1, “ ………… Verse 1 text ………… “

    if VerseNumber = 2, “ ………… Verse 2 text ………… “

    if VerseNumber = 3, “ ………… Verse 3 text ………… “

    }

    If I pass a 1 into the Verses function, I get the text for the first verse. Same with 2 and 3. I can add as many verses as I want or change them around—this is the only place that I have to update. The main song template hides these details.

    The beauty of this setup is that I can rearrange the order of the verses and hooks without rewriting any of the actual text. For example, if a song begins within a chorus, has a verse, and then an ending chorus, the main song template would look like this:

    Chorus();

    Verse(1);

    Chorus();

    After I graduated college, I dabbled in some independent video game development work, and my pre-teen rhyme-writing lessons came into play. The artists may change, but the template stays the same. There are many elements that are common to all games.

    GameInitialize(); → Load game into memory, set the frame rate

    GameStart(); → Set initial game settings

    GamePaint(); → Paint the game’s graphics onto the screen

    GameCycle(); → Manage the gameplay logic during one cycle (defined by the frame rate). This can be everything from changing the direction of a Tetris piece to updating the damage or health of enemies on a screen.

    GamePause(); → Pause the game

    GameUnPause(); → Unpause the game

    GameEnd(); → Show game ending screen, clean game from memory

    Each game that I worked on defined the specifics of each function different, but they all shared this general structure. And it goes back to the notebook.

    To all my hip hop heads, keep studying songs and writing your own rhymes. You never know where it can lead. The world is yours!

    / / 26 COMMENTS

    / / / /

    Start the discussion at bbs.boingboing.net