Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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. :-)


Replies are listed 'Best First'.
Re^5: Burned by precedence rules (== true)
by ikegami (Patriarch) 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.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://733329]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-05-18 14:22 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (71 votes). Check out past polls.