Boost logo

Boost :

Subject: Re: [boost] [signals2] Test failure in C++11 (trivial fix for incorrect usage of boost::optional)
From: Frank Mori Hess (fmh6jj_at_[hidden])
Date: 2014-02-28 13:04:26


On Fri, Feb 28, 2014 at 11:26 AM, Peter Dimov <lists_at_[hidden]> wrote:
> 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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk