in reply to Re^6: Anybody use !!
in thread Anybody use !!

"If you've learnt to understand it, why do you assume others will be unable to?"

That was not the point. Where this got started, I said that !!$return is a bad idea. The statement essentially returns a flag (boolean) value. Some prior statement should have made to make the return value crystal clear and given it another name other than $return: like $all_accounts_valid or whatever fits the application.

So the first style point is that $return doesn't describe what it is. Yes it is a return value, but what kind of return value? One line of code before the return was needed in my opinion to turn this into a boolean return value.

If you don't agree that using a better name than $return is "easier to understand" and a better style, then things degenerate from there and I have no hope of convincing you otherwise. And yes this will require one statement before the return to make this clear. But..

return $all_data_valid; is better in my opinion than:
return !!$return; There is no need for this confusing !!$return.

This is not a point of whether !!$return can be understood, the point is that there are easier ways of expressing this idea so that it can be easily understood. A Perl return scalar doesn't have a type declaration like in C. Often that very last return line has a lot of contextual meaning. returning a flag like: $all_data_valid is just going to convey more information than !!$return.

Replies are listed 'Best First'.
Re^8: Anybody use !!
by BrowserUk (Patriarch) on Dec 30, 2010 at 13:29 UTC

    Oh, okay. I guess I misunderstood the OP. I thought that he named the variable $return because it was unimportant to his question.

    I can see that if you speculate about the bigger picture, the name of the variable is important:

    sub isAllDataValid { my $return; if( ... ) { $return = thisTest(...); } elsif( .. ) { $return = thatTest(...); } else{ $return = theOthertest(...); } ... return !! $return; }

    And the normalisation of disparate returns is relatively unimportant.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^8: Anybody use !!
by Anonymous Monk on Dec 30, 2010 at 11:49 UTC
    Don't feed the BUKs...

    ... and a happy new year! :)