This website uses cookies to ensure you get the best possible experience. See our Cookies Policy.

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

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

Happy coding, friends.


Posted by Brock Boren

Related Content

thumbnail image

Get Informed

PMG Innovation Challenge Inspires New Alli Technology Solutions

4 MINUTES READ | November 2, 2021

Get Informed

Applying Function Options to Domain Entities in Go

11 MINUTES READ | October 21, 2019

thumbnail image

Get Informed

My Experience Teaching Through Jupyter Notebooks

4 MINUTES READ | September 21, 2019

Get Informed

Trading Symfony’s Form Component for Data Transfer Objects

8 MINUTES READ | September 3, 2019

Get Inspired

Working with an Automation Mindset

5 MINUTES READ | August 22, 2019

Get Informed

Parsing Redshift Logs to Understand Data Usage

7 MINUTES READ | May 6, 2019

Get Inspired

3 Tips for Showing Value in the Tech You Build

5 MINUTES READ | April 24, 2019

thumbnail image

Get Informed

Testing React

13 MINUTES READ | March 12, 2019

Get Inspired

Tips for Designing & Testing Software Without a UX Specialist

4 MINUTES READ | March 6, 2019

Get Informed

A Beginner’s Experience with Terraform

4 MINUTES READ | December 20, 2018

ALL POSTS