Article 62WRB CodeSOD: Expanded Conditionals

CodeSOD: Expanded Conditionals

by
Remy Porter
from The Daily WTF on (#62WRB)

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 matchpublic 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.

proget-icon.png [Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments