It’s no easy task combing through the submissions and choosing the right code sample.
Ulysses knows my pain. He recently inherited a Python codebase with plenty of global variables, no convention around capitalizing identifiers, inconsistent levels of indentation, and an AngularJS front end.
He found this when investigating a bug:
candidateNum=4
if candidateNum == "4":
handleCandidate4()
return true
else:
handleCandidate3()
return true
Once upon a time, this code received candidateNum as an input, and made a decision. Sometime in the past, Ulysses’s predecessor changed it according to a ticket: “Only use the candidate4 settings”. So, he hard-coded in candidateNum = 4 and released the change.
There was only one problem with that. Python’s == operator does strict comparisons. 4 != "4", and never will be. This leads us to think that perhaps the last person to touch this code knew JavaScript a little better than Python, since JavaScript has no type system to speak and happily coerces types silently.
Ulysses removed the conditional logic.
To read the full article, please visit The Daily WTF
No comments:
Post a Comment