develooper Front page | perl.perl5.porters | Postings from March 2021

Re: De-experimentalising "signatures"

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
March 22, 2021 16:55
Subject:
Re: De-experimentalising "signatures"
Message ID:
20210322165526.7425f488@shy.leonerd.org.uk
On Mon, 22 Mar 2021 17:12:19 +0100
Leon Timmermans <fawaka@gmail.com> wrote:

> That does sound reasonable. I'm not sure why we haven't done so
> already; that would have prevented this situation.

Without @_ you can't do arity-checking. E.g. while I personally dislike
the style, a popular thing to do with object accessors is something
like:

  sub name {
    my $self = shift;
    $self->{name} = shift if @_;
    return $self->{name};
  }

That could be written

  sub name ($self, $new = undef) {
    $self->{name} = $new if @_ > 1;
    return $self->{name};
  }

(or something neater with Object::Pad + `method`), but lacking access
to any form of scalar-snail, means we can't distinguish

  $obj->name()

from

  $obj->name(undef)

This is one among a number of reasons why @_ is currently still
required in some situations, for which there are designs on adding more
bits to signatures which will make simpler.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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