On Fri, Feb 28, 2014 at 11:26 AM, Peter Dimov
Frank Mori Hess wrote:
Nothing is a problem once you get used to it. I apologize for using a bit of hyperbole, let me try again. I consider the following obvious: given two expressions like "!x" and "x==false" we have:
desirable behavior: they both compile and mean the same thing. neutral behavior: only one compiles. undesirable behavior: they both compile and mean completely different things.
This is obviously a matter of stylistic preference, but still, mine runs contrary to yours. x == false is an anti-pattern and should never be preferred to !x , even when x is bool; similarly, x == true is an anti-pattern and should never be preferred to plain x. Boolean logic doesn't have ==. Nobody prefers ( x == y ) == false to !( x == y ) or x != y, let alone ( x == y ) == true to x == y.
And when our original x is not bool but, say, a pointer, x == false is just silly, even though it works.
Ok, but when you are going over some code and see "x==false", and decide to refactor it to "!x" for all the reasons you've given, you've just broken the code. Because they mean completely different things for optional<bool>. -- Frank