Michel Fortin wrote:
On 2009-12-07 01:29:14 -0500, Andrei Alexandrescu
<[email protected]> said:
Using double negation !!x throughout, there are only advantages and no
disadvantage. I hit that design with Pacquiao punches over the past
week or so, and couldn't find any shortcoming. It's consistent across
positive and negated uses, easy to understand, easy to define,
consistent with built-in types, and Walter likes it.
I'm not sure that's a great idea. What if you define your own FuzzyBool
type (containing some sort of probability) and FuzzyBool.opUnary!("!")
returns an inverted FuzzyBool (with 1 - original probability) instead of
a regular bool, you'd have an infinite loop trying to evaluate
!!myBoolValue.
Yeah, I thought about that liability and decided to discount it as a
design mistake of the user. If a type decides to return non-bool from
"!", they are bound to unpleasantly surprise its user in more ways than
one. You can define a negate for FuzzyBool - just don't dress it as the
"!" operator.
Andrei