Saturday, July 27, 2024

Maximizing Code Quality – The Daily WTF

Programming LanguageMaximizing Code Quality - The Daily WTF


One of the nice things about Git is that it makes it very easy for us to learn the steps that went into a WTF. It doesn’t mean it explains the WTF, as many are just inexplicable, but it’s at least something.

Like this example, from Aoife.

The JavaScript started like this:

function getData(deviceId) {
    return this.storage.loadSomeData(userId)
}

The function was committed in this state, and remained unchanged for six years. The astute reader may have noticed the problem: the function takes a parameter called deviceId, but references a value called userId, which is not defined here. This is bad, and means this code doesn’t work as it’s supposed to, so after six years, someone finally decided to fix it.

function getData(deviceId) {
    
    return this.storage.loadSomeData(userId)
}

There we are, all better. The function still doesn’t work, but at least the linter doesn’t yell at us anymore.

Of course, there remains a huge, obvious problem with this function, so two years later, someone made a new commit:

function getData(deviceId) {
    
    return this.storage.loadSomeData(userId);
}

Finally, the big problem has been fixed: that missing semicolon.

[Advertisement]
Otter – Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!

Check out our other content

Check out other tags:

Most Popular Articles