in reply to Re: A question about method return values and error checking
in thread A question about method return values and error checking

Because of the context issues you mentioned, I'd use a blank return; instead of return undef;

I hate you! Functions that are expected to return a scalar should not suddenly returning nothing. It rarely has any advantage, and it fails very poorly in common situations.

f( name => get_name(), foo => 1 );

Replies are listed 'Best First'.
Re^3: A question about method return values and error checking
by LanX (Saint) on Nov 09, 2015 at 17:01 UTC
    > f( name => get_name(), foo => 1 );

    That's because the design of => is flawed.

    It should enforce scalar context, if people want to use it as a pairing operator.

    DB<106> sub tst { return } DB<107> x a => scalar( tst() ), b=>2 => ("a", undef, "b", 2)

    And yes I know that Moose relies on this "feature", but you can't have it all.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Well, the Perl 5 implementation of => has that problem. I recall discussions of enforcing scalar context when => was still fairly new, but it was already too late. Then Perl 6 made it so.

      And the problems with return; from a sub that otherwise returns a single scalar go way beyond just uses of =>, of course.

      - tye        

        > go way beyond just uses of =>, of course.

        Well I had the Stop Using Perl discussion in mind.

        Using fat-comma + sub-call has unpredictable consequences, mainly b/c people are led to the misinterpretation that => is pairing two values like e.g. : is doing in JS.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!