CodeSOD: The Difficulties of Choice |
Its 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, Ulyssess 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. Pythons == 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.
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |