-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: The Difficulties of Choice

Четверг, 12 Мая 2016 г. 13:30 + в цитатник

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.

[Advertisement] Scale your release pipelines, creating secure, reliable, reusable deployments with one click. Download and learn more today!

http://thedailywtf.com/articles/the-difficulties-of-choice

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку