develooper Front page | perl.perl5.porters | Postings from September 2023

Re: //= and ||= in subroutine signatures

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
September 4, 2023 13:11
Subject:
Re: //= and ||= in subroutine signatures
Message ID:
ZPXXYA6CPXLR1Mxs@iabyn.com
On Sun, Sep 03, 2023 at 01:28:08PM +0300, Ivan Vorontsov wrote:
> Maybe genuine optional parameters must be only the ones marked by =
> sign. Others are mandatory. To mandatory parameters with //= or ||=
> operators, that are last in the list or precede optional ones with =,
> undef values are assigned, if there are less arguments than mandatory
> parameters, and then operator works with that value.

I think that that's complex and confusing. You're basically saying

    f($x, $y = 1,    $z = 2)    # $y is optional parameter
    f($x, $y //= 1,  $z = 2)    # $y is optional parameter
    f($x, $y //= 1,  $z    )    # $y is mandatory parameter
    f($x, $y //= 1         )    # $y is optional parameter

I think //= and ||= should be consistently either mandatory or optional,
and not vary based on context.

And since there already been a release (5.38) where they're optional, I
think we should keep it that way.

-- 
Decaffeinated coffee is like dehydrated water

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About