PMG Digital Made for Humans

What “The Life of Pablo” Can Teach You About Writing Better Code

3 MINUTE READ | December 12, 2016

What “The Life of Pablo” Can Teach You About Writing Better Code

Author's headshot

Brock Boren

Brock Boren has written this article. More details coming soon.

At 4:59 PM on February 12, 2015, Kanye West premiered “Wolves”, a track featuring Vic Mensa and Sia, at Yeezy Season 1. Yet when the track finally appeared on The Life of Pablo, Mensa and Sia had been excised from the track, instead being replaced by vocals from Frank Ocean. Several days after the release of TLOP, West proclaimed he would “fix wolves”.

ima-fix-wolves

Wolves and the rest of TLOP would undergo several revisions, as chronicled here by Complex and discussed here by Pitchfork. In short, Mr. West has rewritten the rules regarding an album’s post-release life by employing a concept that you should be already be practicing in your code: iteration.

Iteration is simply the process of going back over your code and revising it in order to improve it. To demonstrate my point, take a look at the simple function below.

function multiplyByTwo(num) {    var doubleNum = num*2;

    return doubleNum;}

var double = multiplyByTwo(2);

Our function above takes a number, multiplies it by two, and returns that value.

See any room for improvement?

function multiplyByTwo(num) {    return num*2;}

var double = multiplyByTwo(2);

We don’t need to assign a variable to the num*2 value, we can just return it as it is.

If our entire goal was to build a function that returned double an input’s value, our code would accomplish that goal (although creating a function for that purpose is entirely overkill). But let’s say that we deploy our code to production and later on the need arises to multiply values by 3. Easy fix, right?

function multiplyByThree(num) {    return num*3;}

var triple = multiplyByThree(3);

Hopefully, you can already see where this approach is going to lead. If we continue on like this, we’ll be creating a new function any time that we want to multiply a number by a specific value. Wouldn’t it be easier if we just created one function that multiplied any input by a specified value?

function multiply(num, factor) {    return num*factor;}

var multiple = multiply(5, 10);

console.log(multiple); // output: 50

In the code above, our multiply function takes two arguments, num (the number we want to multiply) and factor (the factor we want to increase num by).

This is a super basic example, but it illustrates the benefits of iterating over your code. A great way to get into this is with exercism. It’s a tool I used when learning how to code and I highly recommend it. If you feel like giving it a shot and want somebody to look over your code, shoot me an email with a link to your exercism profile and I’ll leave you some notes.

Stay in touch

Bringing news to you

Subscribe to our newsletter

By clicking and subscribing, you agree to our Terms of Service and Privacy Policy

Happy coding, friends.


Related Content

thumbnail image

AlliPMG CultureCampaigns & Client WorkCompany NewsDigital MarketingData & Technology

PMG Innovation Challenge Inspires New Alli Technology Solutions

4 MINUTES READ | November 2, 2021

thumbnail image

Applying Function Options to Domain Entities in Go

11 MINUTES READ | October 21, 2019

thumbnail image

My Experience Teaching Through Jupyter Notebooks

4 MINUTES READ | September 21, 2019

thumbnail image

Working with an Automation Mindset

5 MINUTES READ | August 22, 2019

thumbnail image

3 Tips for Showing Value in the Tech You Build

5 MINUTES READ | April 24, 2019

thumbnail image

Testing React

13 MINUTES READ | March 12, 2019

thumbnail image

A Beginner’s Experience with Terraform

4 MINUTES READ | December 20, 2018

ALL POSTS