Front page | perl.perl6.language |
Postings from April 2002
Re: Unary dot
From: Allison Randal
April 10, 2002 15:47
Re: Unary dot
Message ID: 20020410224701.GK13824@shadowed.net
On Thu, Apr 11, 2002 at 08:04:56AM +1000, Damian Conway wrote:
> Allison wrote:
> > $self.foo() => $self->foo() # and can be .foo() when $self is $_
> > .foo() => $_->foo() # but might be altered by a pragma
> > foo() => foo()
> And welcome back to where we started! ;-)
> The problem that this discussion has highlighted is that using a bare
> .foo in a method means the reader/maintainer has to track what the
> current topic is in order to know who the current invocant is. That
> would seem to be a (potentially expensive) hidden cost of this idiom.
But possibly less expensive than providing a means to default to
something other than topic.
> That is, that as well as aliasing the invocant to $_, they also alias it
> to some standard variable name.
> Then one would be guaranteed an invariant name (across all OO Perl!)
> for the invocant, even under internal topicalizations.
I'm in favor of the standardized variable name. It is a restriction, but
not an onerous one. I've never used anything but $self, and I'm sure it
would be easy to adapt to whatever else was chosen. Are there any
statistics availble on current usage of $self vs. $this vs. whatever? It
might be easiest to go with what the majority find most comfortable.