[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Boolean matters
- From: Philippe Lhoste <PhiLho@...>
- Date: Tue, 04 Dec 2012 11:46:44 +0100
On 04/12/2012 10:38, spir wrote:
I never have any use for xor in practice. What examples usage do you have? (I really ask,
i'm interested in knowing when & where we may need it, whether it is worth having it built
in a prog lang).
I use it sometime (in Java), when I find an expression equivalent to:
if a and not b or b and not a then
...
end
Indeed, the opportunities are scarce...
And I feel the need to explain why I use this ^ symbol here...
Mmm, now that I think of it, a simple
if (a != b)
can work in Java, if a and b are boolean! (And might be easier to understand at a glance.)
I tend to stay away from boolean comparisons because if (a == true) seems so redundant to
me (and I often see beginners doing the dreaded if (a = true), the only case where it can
work in Java!), but here it makes sense.
In languages where some various values can be interpreted as true or false, such
comparison doesn't work. Well, unless converting them to true booleans, which lead us back
to the original message! ;-)
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --