develooper Front page | perl.perl5.porters | Postings from February 2015

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

Thread Previous | Thread Next
From:
Ricardo Signes
Date:
February 24, 2015 22:59
Subject:
Re: [perl #123069] signature/attribute syntax is awful
Message ID:
20150224225855.GA23823@cancer.codesimply.com
* Ricardo Signes <perl.p5p@rjbs.manxome.org> [2015-02-24T12:42:57]
> * Zefram <zefram@fysh.org> [2015-02-24T12:37:26]
> > That the signature is part of the body is not an implementation detail,
> > it is fundamental to the definition of signatures.
> 
> As far as the programmer who is writing a subroutine with a signature is
> concerned, how is this relevant, let alone fundamental?

Let me clarify what I'm getting at, here.

Of course it is the case that the signature is equivalent to extra code in the
body.  We could argue about whether this is an implementation detail, but in
the end that isn't the point, I think.

The point is that it is not relevant to the user that the parameter list is
effectively a macro that expands into the interior of the body's braces.  The
user cares that it has the same effect as declarations and assignments in the
body, but not that it is in fact implemented that way.

Moreover, if the user really cared about that, would there really be some
benefit on that front from the parameter list being nearer to the right of the
attributes, rather than the left?

Not an actual quote, but: "The parameter list should be nearer the body because
it is effectively part of the body, while the attribute list is not."  If we
cede that it is effectively part of the body, I *still* don't see that this
implies it should be nearer the body.  I don't think there is a benefit to the
average (or almost any) programmer by that positioning.

Another argument made was that people will think, if the signature is nearer
the name, that the signature should be inspectable metadata.  I don't see it.
Whether it should be inspectable or not is a totally unrelated question, on
which I have a bunch of contradictory opinions that don't inform my feelings
about the parameter list's position relative to he attributes even one bit.

To me, this is a question of anticipating programmers' existing expectations.
In the many other languages with formal parameter lists, the parameters follow
the name directly, and we think about writing "function abc(x,x,y)".  So, too,
I think, will people be thinking about this in Perl 5.  Most subroutines will
be written as "sub abc($x, $y, $z)" and only rarely will an attribute be added.
When it is, I believe it will be much more suprising to need to separate (by
attribute addition) the name and signature than to add the signature before the
brace.

That, I think, is why (as Lukas said and I also experienced)) there have been
(anecdotal, not scientific) reactions from other programmers of "oh, that's
much better."

Finally:  Father C, you talked about perl6 moving the regex flags to the front.
I don't think it's a good analogy.  With the nicely spaced-out grammars one
writes in p6, keeping modifiers at the end magnifies the already unpleasant
"German verb" effect of reading everything else before getting to the regex's
modifier context.  Subroutine signatures are not the same sort of thing.  There
is not going to be a sea of statements dividing parameter list from body.
There will, on some occasions, a short list of attributes.

As for expectations?  Perl 6 subroutines *also* put their parameter list before
their attributes (well, they call them traits).

-- 
rjbs

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