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

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

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

 

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

 -Статистика

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


CodeSOD: Expanded Conditionals

Четверг, 25 Августа 2022 г. 09:30 + в цитатник

A common anti-pattern is the "expanded conditional". You know the drill:

if (a == b && b != c) { return true; } else { return false; }

This could be condensed into a single return statement. It's annoying, and stupid, and frequently part of a WTF, but never a WTF in-and-of-itself.

Except for this one, found by Timo.

// check if the IDs match public bool CheckIfIdMatch(int currentProductId, int foundProductId) { // if the product matches with the target if (currentProductId == foundProductId) { // return true return true; } // else, return false return false; }

This is a perfect block of bad code. It takes a simple task (an equality comparison between integers) and stretches it out to a whole block of code with an expanded conditional. The comments are useless restatements of the code itself. And of course, it's such a "useful" method, it's invoked in all sorts of places throughout the code.

[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

https://thedailywtf.com/articles/expanded-conditionals

Метки:  

 

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

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

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

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