Allison wrote:
> 
> > > "David Whipp" <[EMAIL PROTECTED]> writes:
> > >
> > > > Thus, the perl5 transalations would be:
> > > >
> > > >   foo() => $self->foo()
> > > >   .foo() => $_->foo()
> > > >   &foo() => foo()
> > > >   ...
> 
> Alternative:
> 
>    $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! ;-)

However, having circumnavigated the alternatives, we now have a better
perspective on the trade-offs and hidden costs.

The original idea of topicalizing the invocant in methods was that it makes
very simple methods even simpler:

        method name { .assigned_name // .std_name // "???" }

For anything more complex than "very simple" (i.e. anything with internal
topicalizers), one names the invocant explicitly:

        method rank ($self:) {
                given ($.status) {
                        when "covert"   { return "Special operative" }
                        when "detached" { return "Field operative" }
                        default         { return $self.actual_rank }
                }
        }

or, if the class has many such methods, implicitly:

        use invocant 'invocant'; 

        method rank () {
                given ($.status) {
                        when "covert"   { return "Special operative" }
                        when "detached" { return "Field operative" }
                        default         { return invocant.actual_rank }
                }
        }

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.

Reflecting on this, it seems that it would be useful if methods
implicitly did their default topicalization-of-invocant like so:

        -> $self

rather than just:

        -> $_

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.

Of course, the problem is then: what should the name of this topicalizer
variable be? The main options are:

        $self
        $me
        $I
        $this
        $invocant
        $object
        $obj

And frankly, that's a very minor issue. Someone (i.e. Larry) should just
pick one and then we can all move on.

Damian

Reply via email to