develooper Front page | perl.perl5.porters | Postings from October 2022

Re: Named argument syntax (was Re: PSC #049 2022-01-07)

Thread Previous | Thread Next
From:
Ovid
Date:
October 8, 2022 13:24
Subject:
Re: Named argument syntax (was Re: PSC #049 2022-01-07)
Message ID:
CA+M4CHtzaiFus30xHDLjeyg-e=2-Qg_F0aRmBdo=EuOjSWFQ+A@mail.gmail.com
On Sat, Oct 8, 2022 at 3:18 PM Ovid <curtis.poe@gmail.com> wrote:

> That being said, :\@foo compounds Perl's reputation for linenoise. Can we
> come up with a rule to avoid this? My first thought is:
>
> "Rule 2: named parameters are scalars, with the scalar constrained to an
> array or hash reference, if needed."
>
>
Ouch. I rewrote this email after I rethought things in terms of
non-flattening variables instead of references, but I forgot to fix rule 2.

"Rule 2: named parameters correspond to their named arguments without
flattening, unless explicit name/value pairs are used."

That leads to two calling conventions:

    foo( bar => $bar, baz => \@baz, quux => \%quux );
    # versus
    foo( :$bar, :@baz, :%quux );

In this case, TIMTOWTDI seems confusing because the second syntax seems
much cleaner (and concise) to me, but we'd still have to support the older
syntax. Thus, we still need to have an exception to the rule. I am not sure
that's avoidable, but we'd have the consistency of a leading colon for both
arguments and parameters.

Best,
Curtis "Ovid" Poe
--
CTO, All Around the World
World-class software development and consulting
https://allaroundtheworld.fr/

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