Which is clearer form: if(!value) or if(flag == value) ?
Posted
by CodexArcanum
on Stack Overflow
See other posts from Stack Overflow
or by CodexArcanum
Published on 2010-06-04T19:57:38Z
Indexed on
2010/06/07
2:22 UTC
Read the original article
Hit count: 246
c#
I understand this is a subjective question, so I apologize if it needs to be closed, but I feel like it comes up often enough for me to wonder if there is a general preference for one form over the other.
Obviously, the best answer is "refactor the code so you don't need to test for falsehood" but sometimes there's no easy way to do so and the "else" branch is simply to continue processing. So when you must have an "if not false" construct, which is the preferred standard:
The not operator
if(!value)
Or the test for false
if(value == false)
© Stack Overflow or respective owner