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

sub signatures - stepping back

Thread Next
From:
Peter Martini
Date:
October 28, 2012 10:36
Subject:
sub signatures - stepping back
Message ID:
CAFyW6MT22V3wmabnN9ViqF17EgKBK9d=7=MYTaa0wK2m2vVa=g@mail.gmail.com
Stepping back a bit:

I haven't seen anyone argue against adding hooks for signatures, so it
seems like that's worth splitting out separately to hammer out the details
of the API.

An in-core implementation is a separate discussion.

The key points:

* The feature will be lexically scoped.

* It's effects will be limited to the sub's defined while the feature is in
effect.

* If the feature is in effect, and a sub is defined without a signature, it
will behave *exactly* as if the feature was not in effect.  Completely
necessary in case this becomes, at some point, a default feature.

* Because the feature can be turned off, but hooks will be exposed, it
doesn't make much difference to something like Moose

* traditional prototypes will still be accessible via a : prototype()
attribute.  This also benefits alternate implementations.

* Note that arity checking does count as having an effect only within the
sub where a signature is used, as it will be die'ing in that sub in exactly
the same manner as if someone had explicitly written die if $#_ > 1 etc.

Points of contention:

* Should parameter checking be strict?

* Should @_ be banned?

(I don't know if this was sufficiently discussed.  The reasoning was to
allow for a potential future performance boost, by not having to initialize
@_; I'm not sure if there were other reasons).


*************************

I think its worth revisiting the discussion around @_, since the banning of
@_ makes arity checking impossible for the sub writer.  If @_ is still
allowed, then it becomes the sub writers choice if they want to make sure
that undef in the last position was an actual undef and not simply the
automatic default value.


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