develooper Front page | perl.perl5.porters | Postings from December 2014

Re: [perl #123069] signature/attribute syntax is awful

Thread Previous | Thread Next
From:
Peter Martini
Date:
December 9, 2014 13:23
Subject:
Re: [perl #123069] signature/attribute syntax is awful
Message ID:
CAFyW6MTQfUF4S6aPN7jOvp5ALBbkHXCGTLSyqrqbrUiuti45FQ@mail.gmail.com
On Mon, Oct 27, 2014 at 6:29 PM, l.mai@web.de <perlbug-followup@perl.org>
wrote:

> # New Ticket Created by  l.mai@web.de
> # Please include the string:  [perl #123069]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=123069 >
>
>
> The syntax 'sub foo :attributes ($signature) { ... }' is awful. It should
> be 'sub foo($signature) :attributes { ... }'. (This might be a candidate
> for bug #121481.)
>
> Why? Because syntactically the signature replaces what used to be the
> prototype, and that comes before attributes. It's also what all signature
> modules on CPAN implement.
>
> It's also what perl itself does in C. :-)
>
>   OP* Perl_newDEFSVOP(pTHX) __attribute__((warn_unused_result));
>
> not
>
>   OP* Perl_newDEFSVOP __attribute__((warn_unused_result)) (pTHX);
>
> (I have no idea if that would even parse.)
>
>
+1 to moving signatures before attributes (and -1 to allowing it both
ways).  I'll also note that having the signature after attributes leads to
an unfortunate and unnecessary case of significant whitespace:

sub foo : attributes ($signature) {}  # signature of '$signature', and an
attribute of 'attributes'
sub foo : attributes($signature) {}   # no signature, and an attribute of
'attributes'

There's no such ambiguity if the signature is before the attributes

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