Article 6MGVB CodeSOD: Totally Valid

CodeSOD: Totally Valid

by
Remy Porter
from The Daily WTF on (#6MGVB)

Greg's co-worker really wanted to make sure that a variable was correctly set to true or false. So they did this:

if (isValid == true){isValid = true;}else{isValid = false;}

If isValid is true, set it to true, otherwise set it to false. isValid is a boolean in C#, so the only options it could have are true and false.

The real WTF is that in languages with truthiness, this code may actually be useful- converting a falsey value to a literal false. But in C#, this is both useless and stupid.

otter-icon.png [Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!
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