This is what you get when you measure lines of code
A few months ago, I wrote an article about a technical leader who misunderstood how to measure code quality. Trying to improve things, his only achievement was to make everything worse, because of the way bad measuring impacts a team.
One reader of this blog contacted me to share a funny piece of code. He inherited it from a team where measurements were made, but with absolutely no thought about the impact those measurements can have. One factor was the lines of code committed per sprint. It wasn't that the paycheck was proportional to the LOCs, but rather that the team was receiving congratulations or reprimands based on how many LOCs they produced. The person who was writing the least number of lines was requested to explain in front of the team why he wasn't performing as well as his colleagues.
Here's the result of a one-liner (a simple binding of a visibility of a control to a boolean) transformed into thirty-five lines of text. The guys who wrote it are absolutely amazing. In particular, I love the perfectly useless comments which barely repeat the code, line after line, the if/else
split into two separate conditions, and, naturally, the ingenious use of an intermediary variable.
// Initialize the account disabled variable.
let isAccountDisabled;
// Assign user object to a local variable.
const accountInformation = this.user;
// If the disabled attribute from the account information is set to true...
if (accountInformation.disabled) {
// ... then assign true to the variable.
isAccountDisabled = true;
}
// If the account is not disabled...
if (!accountInformation.disabled) {
// ... then assign false to the variable.
isAccountDisabled = false;
}
// Make sure the variable is a boolean.
isAccountDisabled = !!isAccountDisabled;
// If the variable isAccountDisabled is true...
if (isAccountDisabled) {
// ... then display a message in the console...
console.log('The account is disabled.');
// ... and show the popup.
this.showDisabledAccountPopup = true;
}
// If the variable isAccountDisabled is false...
if (isAccountDisabled) {
// ... then hide the popup.
this.showDisabledAccountPopup = false;
}