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

sub signatures - stepping back

Thread Next
Peter Martini
October 28, 2012 10:36
sub signatures - stepping back
Message ID:
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

* 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About