Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 9
    For this very reason, a C++ project I worked on for some medical device software had a coding standard which mandated == false instead of ! for this same reason (to make it stand out). However there was no requirement to use == true, so any non-zero value still worked as it should. Commented Feb 26, 2012 at 0:43
  • 14
    I've always found this argument unconvincing - there are other places in C/C++/C#/Java/etc where failing to see a single character has a similarly significant impact on the interpretation of the code; singling out "!" as the only bad one doesn't make sense to me. Commented Feb 27, 2012 at 8:18
  • 6
    @bevan Apparently you have not been bitten yet. Commented Feb 27, 2012 at 11:46
  • 2
    While I agree that overlooking ! is probably the most troublesome mistake of this kind, this should IMO not give rise to making a habit of writing ==false but of writing better unit tests. Commented Feb 27, 2012 at 13:04
  • 8
    @ThorbjørnRavnAndersen Quite the reverse - I've been bitten often enough over the years that I've taught myself to read every character. I'm not the author of all (or even most) of the code I have to read day to day, so any personal convention as we're discussing here has minimal value: I need to correctly understand all the code I read, not just the stuff I've written. Commented Feb 27, 2012 at 18:00