Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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


Comment on Re^4: Burned by precedence rules (== true)
Download Code
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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2015-07-07 09:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls