Article 6NA52 CodeSOD: Maximizing Code Quality

CodeSOD: Maximizing Code Quality

by
Remy Porter
from The Daily WTF on (#6NA52)

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) { // eslint-disable-next-line no-undef 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) { // eslint-disable-next-line no-undef return this.storage.loadSomeData(userId);}

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

otter-icon.png [Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments