Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

triple negation - an idiom?

by morgon (Priest)
on Dec 07, 2014 at 23:07 UTC ( #1109503=perlquestion: print w/replies, xml ) Need Help??

morgon has asked for the wisdom of the Perl Monks concerning the following question:

The Time::Limit module (as featured in the advent calendar) contains this:
if ( !!! fork ) {
and I wonder what exactly is achieved by using a triple negation?
Is this just an element of style (a la "I do it because I can") or is this some idiom that serves some deeper purpose?

Please enlighten me...

Replies are listed 'Best First'.
Re: triple negation - an idiom?
by LanX (Archbishop) on Dec 07, 2014 at 23:19 UTC
    Double negation has a meaning ( normalize boolean expression), but I agree that triple doesn't improve a simple negation.

    Cargo cult? Playing safe? Who knows ! :)


    Disclaimer: I'm not aware of any special magic of fork , but who knows .. it's Perl ;)

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re: triple negation - an idiom?
by tobyink (Canon) on Dec 08, 2014 at 10:48 UTC

    I was reading your question and thought to myself "probably some idiot thought it looked cute"... and then I noticed that it was Time::Limit, so that idiot was me!

    Yeah, I probably thought it looked cute, or would stand out better, or something like that. It achieves nothing over a single negation.

    In the case of overloaded objects, it actually could return something different from a single negation, but fork ain't likely to ever return an overloaded object.

Re: triple negation - an idiom?
by blindluke (Hermit) on Dec 08, 2014 at 07:17 UTC

    I'm guessing it's there for readability. Someone might have missed the negation once before and figured out that by adding two more exclamation marks the logic stays the same, but he will not miss it the second time. So it's there for emphasis, like 'NOT' instead of 'not' in a plain text sentence. This would be my guess.

    I would probably just use 'unless'.

    - Luke

Re: triple negation - an idiom?
by QM (Parson) on Dec 08, 2014 at 11:00 UTC
    Update: clarified for boolean...

    Considering the previous responses, I'll throw my 2p in.

    I prefer the named operators, such as not to !, because they don't disappear as easily into the punctuation forest that Perl sometimes turns into.

    (Which makes me think that not not would be the named unary positive operator for booleans, just like + is the positive sign operator. Maybe a nice alias like aye instead?)

    Quantum Mechanics: The dreams stuff is made of

      No, not not can't be used as a non-punctuation equivalent to the unary +.

      not not 2 is equal to 1.

        Yes, agreed. I was thinking of Booleans, where it's not an issue. Though my telepathy is in the shop this week.

        Quantum Mechanics: The dreams stuff is made of

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1109503]
Approved by kevbot
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2020-01-21 04:59 GMT
Find Nodes?
    Voting Booth?