Possible Duplicate:
Make a big deal out of == true?
When I was a young padawan in the world of programming, a person I considered a mentor told me that if statements are more aesthetically pleasing if written in the following way:
if (condition == false) {
doSomething()
}
or
if (condition == true) {
doSomething()
}
I personally found that in the first case it's true, or at least it's easier to read than
if (!condition) {
doSomething()
}
In the "true" case, it's probably an overkill.
So I just use it when I want to test the condition for the "false" case.
Almost all my current coworkers tell me that way is plain wrong.
Does writing the if statements like that have a performance problem? Am I wasting milliseconds on each evaluation by doing it like that?
Sonar reports them as too complex
Can you convince me to not do it anymore? ...or that it's ok to do it like that?
Almost all my current coworkers tell me that way is plain wrong
And what's their reasoning? If there isn't none, or it's something vague like "performance", don't bother.Does writing the if statements like that have a performance problem?
Nope.Can you convince me to not do it anymore? ...or that it's ok to do it like that?
For such minor things, it doesn't really matter. If your team has a code conventions document, follow it. But that's not because there is a problem either way...Sonar reports them as too complex
Deal with everything else first...== false
case, which I don't think those questions address. Should I make it more explicit in the question?== false
are any different to those for== true
.