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

Re: Twigils

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
August 30, 2021 12:00
Subject:
Re: Twigils
Message ID:
YSzINJzEcGHZjYlv@iabyn.com
On Thu, Aug 12, 2021 at 11:24:43AM +0000, Ovid via perl5-porters wrote:
> We're working on the Corinna RFC and it won't be sent soon, but due to
> Corinna's design, we have a subtle issue that isn't shared by most other
> OO languages. In short, lexical variables (declared in a method or in a
> signature) can hide the instance variables. Twigils is one way of
> solving that issue.

1) Note I am not (yet) very familiar with Corinna.

2) My main comment is that I don't mind the idea of twigils in principle.

A couple of further observations (bearing in mind (1)):

3) I like the idea that they should be optional, only needing to be used
when necessary to disambiguate. I.e.

    class Foo {
        has $x;
        method inc ($i) { $x += $i }
        method set ($x) { $:x = $x } # only ambiguous here
    }

4) (bikeshedding) I prefer $.x over $:x. The former has the idea (from C
etc) of accessing an element. $:x is visually similar to my
(currently stalled) proposal for named parameters in signatures:

    sub foo (:$x, :$y) { ... }
    foo(y => 1, x => 0);

Both $:x and $.x suffer from the same parsing ambiguities, in that both $.
and $: are legal variables (although $. is much more commonly used):

    $x < $.or;
    $x < $. or next;

-- 
All wight. I will give you one more chance. This time, I want to hear
no Wubens. No Weginalds. No Wudolf the wed-nosed weindeers.
    -- Life of Brian

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