### Re^4: Burned by precedence rules (== true)

by demerphq (Chancellor)
 on Dec 30, 2008 at 19:50 UTC ( #733329=note: print w/replies, xml ) Need Help??

in reply to Re^3: Burned by precedence rules (== true)
in thread Burned by precedence rules

I'm sure i shouldnt say this, but more than once I have written

if ( !\$x == !\$y ) { ... } if ( !\$x != !\$y ) { ... }

which I think is a fair exception to your rule. I kinda view ! and !! as "boolean constructors", and so long as both sides of your (in)equality are guaranteed to be a "boolean" obtained one of these constructors you can compare them.

But I'm really just nit-picking. :-)

---
\$world=~s/war/peace/g

Replies are listed 'Best First'.
Re^5: Burned by precedence rules (== true)
by ikegami (Pope) on Dec 30, 2008 at 20:09 UTC

There's a logical operator for that: xor

if ( !\$x == !\$y) ) # bool(\$x) == bool(\$y) if ( !\$x != !\$y ) # bool(\$x) != bool(\$y)
can be written as
if ( !(\$x xor \$y) ) # bool(\$x) == bool(\$y) if ( \$x xor \$y ) # bool(\$x) != bool(\$y)

Unforunately, both sets have readability issues.

In Perl 6 we can use positive boolean context, which helps readability a little:
if ?\$x == ?\$y {...} if ?\$x != ?\$y {...}
We can use junctions, which again helps the different case more than the same case:
if not \$x ^ \$y {...} if \$x ^ \$y {...}
or if you prefer:
if !one(\$x,\$y) {...} if one(\$x,\$y) {...}
That's probably enough ways to do it...

Nah. Clearly this demonstrates the utility of a few "Boolean comparison" operators:

if \$isFree ?= \$isEasy if \$isOne !?= \$isOther unlink \$dev eqv unlink \$prod or die "Inconsistent state"; system \$verifyUser neqv system \$verifyAdmin or die "You are not just either a User or an Admin";

;)

- tye

Ah yes, scalar xor, i always forget about it. Personally the !\$x == !\$y makes more sense to me than !(\$x xor \$y). But whatever.

---
\$world=~s/war/peace/g

Create A New User
Node Status?
node history
Node Type: note [id://733329]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2018-03-19 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (240 votes). Check out past polls.

Notices?