Mailing List Archive

Twigils
'cuz we know y'all love a debate ...
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.
I've described it in more detail here: https://github.com/Ovid/Cor/issues/29

We have not made a decision, but we'd like to know if P5P would consider this acceptable or not. We know that for many people, twigils can be a hot-button issue.
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl
Re: Twigils [ In reply to ]
On Thu, 12 Aug 2021 11:24:43 +0000 (UTC)
Ovid via perl5-porters <perl5-porters@perl.org> wrote:

> 'cuz we know y'all love a debate ...
> 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. I've described it in more detail here:
> https://github.com/Ovid/Cor/issues/29
>
> We have not made a decision, but we'd like to know if P5P would
> consider this acceptable or not. We know that for many people,
> twigils can be a hot-button issue.

It should also be noted that this is one of the rare few design
decisions we're having to treat entirely theoretically, based purely on
people's thoughts and opinions, and we can't back it up with observed
fact from actual practice.

This is because core perl doesn't make it possible (or at least, I
haven't found a way to make it possible) to try implementing twigils in
Object::Pad. Many of the other design shapes and choices in Corinna
have been tested out experimentally by writing real code in
Object::Pad, but this particular issue doesn't lend itself to such
experimentation.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Twigils [ In reply to ]
* Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> [2021-08-12 13:48:29 +0100]:

> On Thu, 12 Aug 2021 11:24:43 +0000 (UTC)
> Ovid via perl5-porters <perl5-porters@perl.org> wrote:
>
> > 'cuz we know y'all love a debate ...
> > 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. I've described it in more detail here:
> > https://github.com/Ovid/Cor/issues/29
> >
> > We have not made a decision, but we'd like to know if P5P would
> > consider this acceptable or not. We know that for many people,
> > twigils can be a hot-button issue.
>
> It should also be noted that this is one of the rare few design
> decisions we're having to treat entirely theoretically, based purely on
> people's thoughts and opinions, and we can't back it up with observed
> fact from actual practice.
>
> This is because core perl doesn't make it possible (or at least, I
> haven't found a way to make it possible) to try implementing twigils in
> Object::Pad. Many of the other design shapes and choices in Corinna
> have been tested out experimentally by writing real code in
> Object::Pad, but this particular issue doesn't lend itself to such
> experimentation.

I feel compelled to point out that this is heading in the wrong direction.

This was apparent to me when I had to consult Perl 6/Raku documentation to
see what a "twigil" was.

https://docs.raku.org/language/variables

So if there is a "debate" to be had (here), it would be regarding how
far from "trad" perl 5 you wish to deviate. My concern is that it is
heading towards Perl 6/Raku - the risk being that you'll lose the core
perl 5 audience and find yourself competing with Raku, which has a 20
yr head start.

Bear in mind, I have no issues with Raku; but I think it'd be virtual
suicide for any effort that is trying to improve the POOP experience
for Perl 5 and it's large, diverse base of users.

Thoughts?
Brett

>
> --
> Paul "LeoNerd" Evans
>
> leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
> http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: Twigils [ In reply to ]
On Thu, Aug 12, 2021 at 10:51 AM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> * Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> [2021-08-12 13:48:29
> +0100]:
>
> > On Thu, 12 Aug 2021 11:24:43 +0000 (UTC)
> > Ovid via perl5-porters <perl5-porters@perl.org> wrote:
> >
> > > 'cuz we know y'all love a debate ...
> > > 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. I've described it in more detail here:
> > > https://github.com/Ovid/Cor/issues/29
> > >
> > > We have not made a decision, but we'd like to know if P5P would
> > > consider this acceptable or not. We know that for many people,
> > > twigils can be a hot-button issue.
> >
> > It should also be noted that this is one of the rare few design
> > decisions we're having to treat entirely theoretically, based purely on
> > people's thoughts and opinions, and we can't back it up with observed
> > fact from actual practice.
> >
> > This is because core perl doesn't make it possible (or at least, I
> > haven't found a way to make it possible) to try implementing twigils in
> > Object::Pad. Many of the other design shapes and choices in Corinna
> > have been tested out experimentally by writing real code in
> > Object::Pad, but this particular issue doesn't lend itself to such
> > experimentation.
>
> I feel compelled to point out that this is heading in the wrong direction.
>
> This was apparent to me when I had to consult Perl 6/Raku documentation to
> see what a "twigil" was.
>
> https://docs.raku.org/language/variables
>
> So if there is a "debate" to be had (here), it would be regarding how
> far from "trad" perl 5 you wish to deviate. My concern is that it is
> heading towards Perl 6/Raku - the risk being that you'll lose the core
> perl 5 audience and find yourself competing with Raku, which has a 20
> yr head start.
>
> Bear in mind, I have no issues with Raku; but I think it'd be virtual
> suicide for any effort that is trying to improve the POOP experience
> for Perl 5 and it's large, diverse base of users.
>

This seems like a pointless concern. We don't need to make decisions for
Perl based on whether they are Rakuish or not and nobody aside from us will
care. Past feature imports from Raku have varied from widely successful to
terrible failures, each needs to be judged on its effect on Perl rather
than its effect on Raku. However, this is not even a feature, it's syntax.

-Dan
Re: Twigils [ In reply to ]
* Dan Book <grinnz@gmail.com> [2021-08-12 11:06:15 -0400]:

> On Thu, Aug 12, 2021 at 10:51 AM Oodler 577 via perl5-porters <
> perl5-porters@perl.org> wrote:
>
> > * Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> [2021-08-12 13:48:29
> > +0100]:
> >
> > > On Thu, 12 Aug 2021 11:24:43 +0000 (UTC)
> > > Ovid via perl5-porters <perl5-porters@perl.org> wrote:
> > >
> > > > 'cuz we know y'all love a debate ...
> > > > We're working on the Corinnainna RFC and it won't be sent soon, but due
> > > > to Corinnainna'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. I've described it in more detail here:
> > > > https://github.com/Ovid/Corinna/issues/29
> > > >
> > > > We have not made a decision, but we'd like to know if P5P would
> > > > consider this acceptable or not. We know that for many people,
> > > > twigils can be a hot-button issue.
> > >
> > > It should also be noted that this is one of the rare few design
> > > decisions we're having to treat entirely theoretically, based purely on
> > > people's thoughts and opinions, and we can't back it up with observed
> > > fact from actual practice.
> > >
> > > This is because core perl doesn't make it possible (or at least, I
> > > haven't found a way to make it possible) to try implementing twigils in
> > > Object::Pad. Many of the other design shapes and choices in Corinnainna
> > > have been tested out experimentally by writing real code in
> > > Object::Pad, but this particular issue doesn't lend itself to such
> > > experimentation.
> >
> > I feel compelled to point out that this is heading in the wrong direction.
> >
> > This was apparent to me when I had to consult Perl 6/Raku documentation to
> > see what a "twigil" was.
> >
> > https://docs.raku.org/language/variables
> >
> > So if there is a "debate" to be had (here), it would be regarding how
> > far from "trad" perl 5 you wish to deviate. My concern is that it is
> > heading towards Perl 6/Raku - the risk being that you'll lose the core
> > perl 5 audience and find yourself competing with Raku, which has a 20
> > yr head start.
> >
> > Bear in mind, I have no issues with Raku; but I think it'd be virtual
> > suicide for any effort that is trying to improve the POOP experience
> > for Perl 5 and it's large, diverse base of users.
> >
>
> This seems like a pointless concern. We don't need to make decisions for
> Perl based on whether they are Rakuish or not and nobody aside from us will
> care. Past feature imports from Raku have varied from widely successful to
> terrible failures, each needs to be judged on its effect on Perl rather
> than its effect on Raku. However, this is not even a feature, it's syntax.

You might think so, but back in the early 2000s when Perl 6 was getting off the
ground I could not follow once it started exploring non-Perl 5 concepts. As a
result, Perl 6 became just a curiosity to me but nothing more.

I'm only sharing a single perspective in hopes that Corinna can result in a
complemenary improvement to Perl 5 ... not yet another iceberg that is
cleaved off of this glacier that is Perl 5.

So my question more clearly is; are you trying to reimplement Perl 6 again or
are you trying to create a complementary POOP that trad Perl 5 programms will
a) consider using; but more importantly b) not refuse to maintain code that uses
it? These questions precisely define where "I'm at" in regards to all this. You
start talking stuff like "twigles" or in terms I don't recognize, then it becomes
outside of my periphery. And I'm trying to be charitable here because this seems
like a "canary in the coal mine" moment; and as I've stated before, I really want
to see this effort succeed.

Cheers,
Brett

>
> -Dan

--
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native
Re: Twigils [ In reply to ]
On Thu, Aug 12, 2021 at 6:25 AM Ovid via perl5-porters <
perl5-porters@perl.org> wrote:

> In [Corrina], lexical variables (declared in a method or in a signature)
> can hide the instance variables.
>

This doesn't apply to Perl because instance variables already have their
own syntax. In short,

my $myflag;

and

$self->{myflag};

already don't collide.


NOT A PROBLEM, CLOSE TICKET.
Re: Twigils [ In reply to ]
On Thu, Aug 12, 2021 at 11:38 AM David Nicol <davidnicol@gmail.com> wrote:

>
>
> On Thu, Aug 12, 2021 at 6:25 AM Ovid via perl5-porters <
> perl5-porters@perl.org> wrote:
>
>> In [Corrina], lexical variables (declared in a method or in a signature)
>> can hide the instance variables.
>>
>
> This doesn't apply to Perl because instance variables already have their
> own syntax. In short,
>
> my $myflag;
>
> and
>
> $self->{myflag};
>
> already don't collide.
>
>
> NOT A PROBLEM, CLOSE TICKET.
>

This is not relevant to Corinna.

-Dan
Re: Twigils [ In reply to ]
sorry, I just became aware of Corrina today.

https://github.com/Ovid/Cor/wiki/Corinna-Overview

Could Corinna give instance variables their own syntax, differentiating
them from Perl's lexicals and package variables?

$::thing; # package var
$thing; # lexical, if defined, otherwise package
i_thing; # Corinna instance variable (or something... placeholder, not
proposal)

okay read the thing Ovid asked for comments about, I seem to have restated
the question.

On Thu, Aug 12, 2021 at 10:46 AM Dan Book <grinnz@gmail.com> wrote:

> On Thu, Aug 12, 2021 at 11:38 AM David Nicol <davidnicol@gmail.com> wrote:
>
>> On Thu, Aug 12, 2021 at 6:25 AM Ovid via perl5-porters <
>> perl5-porters@perl.org> wrote:
>>
>>> In [Corrina], lexical variables (declared in a method or in a
>>> signature) can hide the instance variables.
>>>
>>
>> This doesn't apply to Perl because instance variables already have their
>> own syntax.
>>
>> This is not relevant to Corinna.
>
--
"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash
Re: Twigils [ In reply to ]
> On Aug 12, 2021, at 2:21 PM, David Nicol <davidnicol@gmail.com> wrote:
>
[…]
> Could Corinna give instance variables their own syntax, differentiating them from Perl's lexicals and package variables?

At some level that’s exactly what a twigil is. You just spell it differently here than Curtis did.

-Chris

-Chris
Re: Twigils [ In reply to ]
On Thu, 12 Aug 2021 at 19:25, Ovid via perl5-porters <perl5-porters@perl.org>
wrote:

> 'cuz we know y'all love a debate ...
>
> 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.
>
> I've described it in more detail here:
> https://github.com/Ovid/Cor/issues/29
>
> We have not made a decision, but we'd like to know if P5P would consider
> this acceptable or not. We know that for many people, twigils can be a
> hot-button issue.
>

Personally I'd suggest that enforcing twigils would be a bad idea, for
reasons including the following:

- shadowing is sometimes desirable, and already applies to any variable
(`our` / `my`)
- it's easily supported with current syntax if you use `$_slot`, as already
found in CPAN examples
- it causes extra work when refactoring between proof-of-concept and
instance method
- if you have a lexical variable with the same name as a slot, then
conceptually that's a naming problem, not a syntax one - putting them in
different namespaces doesn't fix the original problem at all
- it'll be introducing a new concept and syntax with potential for more
confusion

Being able to move code around and use slots, parameters or something
pulled in from an outer scope _without any change at all_ has been very
useful when working with Object::Pad-based projects. The only argument I'd
have in favour of twigils would be "it allows a $self slot", and that's far
outweighed by the points against it.

I would also recommend that anyone proposing twigils should at least spend
some time working with Object::Pad code using the `$_emulated_twigil`
syntax, trying a few refactoring and code evolution tasks, rather than
taking a purely academic approach. The separate namespace aspect appealed
to me at first, for example - especially with a C++ background - but it
didn't take long to change my mind after moving a few blocks of code around.
Re: Twigils [ In reply to ]
On 2021-08-13 12:16 a.m., Tom Molesworth via perl5-porters wrote:
> Personally I'd suggest that enforcing twigils would be a bad idea, for reasons
> including the following:
>
> - if you have a lexical variable with the same name as a slot, then conceptually
> that's a naming problem, not a syntax one - putting them in different namespaces
> doesn't fix the original problem at all
>
> I would also recommend that anyone proposing twigils should at least spend some
> time working with Object::Pad code using the `$_emulated_twigil` syntax, trying
> a few refactoring and code evolution tasks, rather than taking a purely academic
> approach. The separate namespace aspect appealed to me at first, for example -
> especially with a C++ background - but it didn't take long to change my mind
> after moving a few blocks of code around.

I believe the best way to design this is to do something that directly mirrors
the current blessed hashref approach, which is that you ALWAYS reference a slot
in terms of a subscript of an object of the type.

The blessed hash way:

$self->{x}
$other->{y}
(any appropriate value expression)->{z}

The Corinna way:

$self->!x
$other->!y
(any appropriate value expression)->!z

Or something like that.

When I say that slots should have their own namespace, the above is what I
really mean, each object such as $self or $other IS the namespace for the slots,
and all other kinds of Perl variables continue to scope/behave as they did before.

We really don't need twigils, but we do need the "->" alternative to mean its a
slot direct access, whereas plain -> would apply to a defined :reader etc if and
only if they exist.

-- Darren Duncan
Re: Twigils [ In reply to ]
On Fri, 13 Aug 2021 at 15:59, Darren Duncan <darren@darrenduncan.net> wrote:

> On 2021-08-13 12:16 a.m., Tom Molesworth via perl5-porters wrote:
> > Personally I'd suggest that enforcing twigils would be a bad idea, for
> reasons
> > including the following:
> >
> > - if you have a lexical variable with the same name as a slot, then
> conceptually
> > that's a naming problem, not a syntax one - putting them in different
> namespaces
> > doesn't fix the original problem at all
> >
> > I would also recommend that anyone proposing twigils should at least
> spend some
> > time working with Object::Pad code using the `$_emulated_twigil` syntax,
> trying
> > a few refactoring and code evolution tasks, rather than taking a purely
> academic
> > approach. The separate namespace aspect appealed to me at first, for
> example -
> > especially with a C++ background - but it didn't take long to change my
> mind
> > after moving a few blocks of code around.
>
> I believe the best way to design this is to do something that directly
> mirrors
> the current blessed hashref approach, which is that you ALWAYS reference a
> slot
> in terms of a subscript of an object of the type.
>

Strong disagreement from me on this - after using Object::Pad for a while,
it's painful to go back to the old approaches.

Slot access is a common operation, so I find the single-character Huffman
encoding we have now to be an excellent fit.
Re: Twigils [ In reply to ]
From the keyboard of Darren Duncan [13.08.21,00:58]:
[..]
> I believe the best way to design this is to do something that directly
> mirrors the current blessed hashref approach, which is that you ALWAYS
> reference a slot in terms of a subscript of an object of the type.
>
> The blessed hash way:
>
> $self->{x}
> $other->{y}
> (any appropriate value expression)->{z}
>
> The Corinna way:
>
> $self->!x
> $other->!y
> (any appropriate value expression)->!z
>
> Or something like that.

I propose $self~>x
This is close enough, but maybe not visually distinct enough. Or is it?

0--gg-

--
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Twigils [ In reply to ]
On 2021-08-13 1:02 a.m., Tom Molesworth via perl5-porters wrote:
> On Fri, 13 Aug 2021 at 15:59, Darren Duncan wrote:
> I believe the best way to design this is to do something that directly mirrors
> the current blessed hashref approach, which is that you ALWAYS reference a slot
> in terms of a subscript of an object of the type.
>
> Strong disagreement from me on this - after using Object::Pad for a while, it's
> painful to go back to the old approaches.
>
> Slot access is a common operation, so I find the single-character Huffman
> encoding we have now to be an excellent fit.

I don't have a problem with the single character Huffman coding as an ADDITIONAL
option. But it needs to be in ADDITION to something like what I proposed,
because that Huffman option itself only gives access to slots for a single
object of the current class while mine works for all objects of the current
class. -- Darren Duncan
Re: Twigils [ In reply to ]
I think the idea of accessing $other's slots is debatable, and shouldn't be
used as a driving factor in this syntax discussion.
In my opinion, anyway, we shouldn't have a default way to access members of
other objects. If that sort of sharing is needed, it should be explicit
with its own interface.

On Fri, Aug 13, 2021, 12:13 Darren Duncan <darren@darrenduncan.net> wrote:

> On 2021-08-13 1:02 a.m., Tom Molesworth via perl5-porters wrote:
> > On Fri, 13 Aug 2021 at 15:59, Darren Duncan wrote:
> > I believe the best way to design this is to do something that
> directly mirrors
> > the current blessed hashref approach, which is that you ALWAYS
> reference a slot
> > in terms of a subscript of an object of the type.
> >
> > Strong disagreement from me on this - after using Object::Pad for a
> while, it's
> > painful to go back to the old approaches.
> >
> > Slot access is a common operation, so I find the single-character
> Huffman
> > encoding we have now to be an excellent fit.
>
> I don't have a problem with the single character Huffman coding as an
> ADDITIONAL
> option. But it needs to be in ADDITION to something like what I proposed,
> because that Huffman option itself only gives access to slots for a single
> object of the current class while mine works for all objects of the
> current
> class. -- Darren Duncan
>
Re: Twigils [ In reply to ]
On Friday, 13 August 2021, 10:31:49 CEST, shmnem <gm@qwurx.de> wrote:


From the keyboard of Darren Duncan [13.08.21,00:58]:
> I propose $self~>x
> This is close enough, but maybe not visually distinct enough. Or is it?

shmnem,
We had discussed possibly using ~> as the "maybe this method exists" operator, so that if we chain:
    if ( $foo~>bar~>baz ) {
        ...    }
You're saying "if all of these methods exist and the final only returns a true value, then ..."
But that absolutely would not be in the MVP.
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl
Re: Twigils [ In reply to ]
On 2021-08-13 2:18 a.m., Veesh Goldman wrote:
> I think the idea of accessing $other's slots is debatable, and shouldn't be used
> as a driving factor in this syntax discussion.
> In my opinion, anyway, we shouldn't have a default way to access members of
> other objects. If that sort of sharing is needed, it should be explicit with its
> own interface.

How is accessing the slots of $other which is of the SAME CLASS debatable? That
is a completely normal and commonly done thing and is what every single other
language in existence (that I know of) does.

If you didn't have that, how would you code the interaction of 2 objects of the
same class by way of internals that code in other classes isn't supposed to see
and hence no :reader or :writer exists?

Now I can understand Corinna having a feature different from other languages
such that it is even more restrictive, however then we need to provide a way to
grant permission to see slots of other objects of the same class.

This then comes back to the proposal I made months ago where something akin to
Raku's "trusts" feature is important, where a class can enumerate what classes
can access their otherwise private things, and in this case one would declare
that a class trusts itself.

-- Darren Duncan

> On Fri, Aug 13, 2021, 12:13 Darren Duncan wrote:
>
> On 2021-08-13 1:02 a.m., Tom Molesworth via perl5-porters wrote:
> > On Fri, 13 Aug 2021 at 15:59, Darren Duncan wrote:
> >     I believe the best way to design this is to do something that
> directly mirrors
> >     the current blessed hashref approach, which is that you ALWAYS
> reference a slot
> >     in terms of a subscript of an object of the type.
> >
> > Strong disagreement from me on this - after using Object::Pad for a
> while, it's
> > painful to go back to the old approaches.
> >
> > Slot access is a common operation, so I find the single-character Huffman
> > encoding we have now to be an excellent fit.
>
> I don't have a problem with the single character Huffman coding as an
> ADDITIONAL
> option.  But it needs to be in ADDITION to something like what I proposed,
> because that Huffman option itself only gives access to slots for a single
> object of the current class while mine works for all objects of the current
> class. -- Darren Duncan
>
Re: Twigils [ In reply to ]
Having given this further thought, I concede that at the moment its hard to
think of good examples where both of the following are true at the same time for
a given class Foo:

1. A method of Foo wants to access a slot S for any other object of the Foo
class besides the $self object.

2. Slot S doesn't have any :reader or :writer or other custom public accessor
method because it isn't okay for non-Foo classes to see it.

Therefore with respect to the MVP of Corinna I withdraw my objection for the
direct access mechanism to slots of Foo being only available for the $self object.

For the MVP I consider it a reasonable compromise to have to declare a public
:reader etc method for situations where a method needs to access slots of $other
in addition to $self.

-- Darren Duncan
Re: Twigils [ In reply to ]
On Thu, Aug 12, 2021, at 7:24 AM, Ovid via perl5-porters wrote:
> We have not made a decision, but we'd like to know if P5P would consider this acceptable or not. We know that for many people, twigils can be a hot-button issue.

I think twigils are a good idea.

--
rjbs
Re: Twigils [ In reply to ]
Please avoid twigils. They are quasi operators. As operators they ought
to be optional.

On Sun, Aug 15, 2021 at 2:09 AM Ricardo Signes <perl.p5p@rjbs.manxome.org>
wrote:

> On Thu, Aug 12, 2021, at 7:24 AM, Ovid via perl5-porters wrote:
>
> We have not made a decision, but we'd like to know if P5P would consider
> this acceptable or not. We know that for many people, twigils can be a
> hot-button issue.
>
>
> I think twigils are a good idea.
>
> --
> rjbs
>
Re: Twigils [ In reply to ]
On Sat, Aug 14, 2021, at 9:32 PM, Philip R Brenan wrote:
> Please avoid twigils. They are quasi operators. As operators they ought to be optional.

It is unclear what you mean by this. Twigils are not operators. (While there may have been an argument to have been made in the days of Perl v3 that sigils were operators, it ceased to hold water in Perl v5, when lexical variables eliminated the necessity of a glob in a symbol table.) Twigils are syntactic extras in the name of a variable that constrain it in some way. The dollar sign means it will be a scalar. The at sign, an array. Ruby uses sigils, of a sort, in a similar way, but largely to indicate scope. Twigils could allow multiple constraints to be applied at once.

But at any rate, do you mean that all operators should be optional? Writing a program without operators is not something to be attempted in Perl 5 for any reason other than stunt programming.

--
rjbs
Re: Twigils [ In reply to ]
Philip,
I do not know what you mean by "quasi operators" or "As operators they ought to be avoided." Perhaps if I followed P5P more closely I would get it, bu I don't. Right now, one of the biggest problems we're having with Corinna is people saying "yes" or "no" without giving concrete explanations or examples of their reasoning.
For example, here's a slot with a twigil:
has $:x;

method inc ($x) {
$:x += $x;
} Here are some of the arguments for and against them.
Pros:
- You can't accidentally shadow class/instance data. (technical)

- Great Huffman encoding for "this is not a regular variable" (social)

- Easy to syntax highlight (technical)


Cons:
- No direct parser support for twigils (technical)

- Is somewhat controversial (social)

- May contribute to "line-noise" complaints (social)


I can't say that I'm "for" twigils, but so far, that's two strong technical and one strong social argument for them. I see a technical argument against them (I don't know how strong it is) and two rather weak social arguments against them.
At the beginning of the discussion, I was leaning away from twigils. I kind of liked them, but I was swayed by the social arguments. Laying out the pros and cons clearly seems to show a strong benefit to using twigils.
So if you have a strong argument for or against them, if you can clearly describe it, give an example, and explain if it's a technical argument or not, I'd love to hear it (I'm quite serious about this because I'm happy to put a gun to the head of twigils, but I can't see any reason to do so at this point.)
Best,Ovid
-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl

On Sunday, 15 August 2021, 03:39:09 CEST, Philip R Brenan <philiprbrenan@gmail.com> wrote:

Please avoid twigils.  They are quasi operators.  As  operators they ought to be optional.

On Sun, Aug 15, 2021 at 2:09 AM Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote:

On Thu, Aug 12, 2021, at 7:24 AM, Ovid via perl5-porters wrote:

We have not made a decision, but we'd like to know if P5P would consider this acceptable or not. We know that for many people, twigils can be a hot-button issue.


I think twigils are a good idea.

-- 
rjbs
Re: Twigils [ In reply to ]
Ovid

2021-8-15 15:19 Ovid via perl5-porters <perl5-porters@perl.org> wrote:

>
> For example, here's a slot with a twigil:
>
> has $:x;
>
> method inc ($x) {
> $:x += $x;
> }
>
>
>
I still don't see how it will go, however we can think about some
candidates.

Twigil:

has $:x;

method inc ($x) {
$:x += $x;
}

Variable:

has $x;

method inc($dX) {
$x = $dX;
}

Hash ref expression:

has x;

method inc($x) {
$self->{x} = $x;
}

I saw your Twitter.

Do you feel like you're being kicked out of the discussion?
Re: Twigils [ In reply to ]
On Tuesday, 17 August 2021, 06:04:48 CEST, Yuki Kimoto <kimoto.yuki@gmail.com> wrote:


> I saw your Twitter.
>> Do you feel like you're being kicked out of the discussion?
Hi Yuki,
No, I do not feel like I'm being kicked out of the discussion. If anything, P5P has definitely been better about the discussions than conversations I've seen elsewhere. No worries :)
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl
Re: Twigils [ In reply to ]
2021-8-17 13:54 Ovid <curtis_ovid_poe@yahoo.com> wrote:

> On Tuesday, 17 August 2021, 06:04:48 CEST, Yuki Kimoto <
> kimoto.yuki@gmail.com> wrote:
>
>
> > I saw your Twitter.
> >
> > Do you feel like you're being kicked out of the discussion?
>
> Hi Yuki,
>
> No, I do not feel like I'm being kicked out of the discussion. If
> anything, P5P has definitely been better about the discussions than
> conversations I've seen elsewhere. No worries :)
>
>
That's good.
Re: Twigils [ In reply to ]
Ovid via perl5-porters wrote on 15 August:
>
> Here are some of the arguments for and against them.
>
> Pros:
> • You can't accidentally shadow class/instance data. (technical)
> • Great Huffman encoding for "this is not a regular variable" (social)
> • Easy to syntax highlight (technical)
>
> Cons:
> • No direct parser support for twigils (technical)
> • Is somewhat controversial (social)
> • May contribute to "line-noise" complaints (social)
>
> I can't say that I'm "for" twigils, but so far, that's two strong technical and one strong social argument for them.

/Are/ these strong arguments, though?

The accidental shadowing argument seems to not hold much merit: We already have that same problem now in /every/ block, including experimental sub signatures, and it should be solved the same way everywhere.

As for the "not a regular variable" argument: Looking at Java, there are no sigils/twigils of course, but there is "this.", which can optionally be prepended to a name to make accessing instance data explicit. Java is kind of verbose by nature, yet few Java coders seem to use this style (except when needed to disambiguate, obviously). I personally /have/ used that coding style in Java for a few years based on the same "not a regular variable" argument and have gotten more than a few funny looks and comments about that. Eventually I gave in and have to admit: My Java code tends to be easier to read without "this.". Therefore, in my mind, the "not a regular variable" argument is also rather weak.

The synhi argument also seems pretty weak. It's /syntax/ highlighting, not semantic highlighting. All variables /should/ look the same. If you really do want to treat instance variables specially, that shouldn't be hard for today's advanced highlighters anyway by virtue of the declaration with `has`, which is easy to parse. My editor of choice doesn't have /very/ advanced highlighting, but I know this is possible with it. No twigils needed for synhi.

I got one more pro for your list, but it's also kind of weak in my opinion: Twigils could be interpolated in a string, a `slot` keyword probably couldn't. But, again, this is in no way different than any other subroutine call, which also can't be interpolated. I'd say not everything /needs/ to be interpolated.


> So if you have a strong argument for or against them, [...]

I suppose I don't? I mean, certainly not a /technical/ argument against. The thing is, I've never really used Raku, so the entire twigil concept is somewhat new to me. I'm sure Raku is great, I just never found the time to understand it. I did look into learning Raku twice, but honestly what put me off both times is all the line noise in the Raku code I looked at. I could hardly even read it.

Perl looks already noisy. Yes, it makes sense for Perl to look that way, but no need to make it worse. This is all stuff people have to invest effort to learn. A lot of the appeal of Corinna to me initially was its simplicity and elegance. Requiring twigils chips away at both of these.

IMHO, twigils should, if introduced at all (and this ought to be a big if), at least be entirely optional. That is, something like the following should be allowed:

class Point {
has $:x :param;
has $y :param;
method move ($dx, $dy) {
$x += $dx;
$:y += $dy;
}
}


--
Arne Johannessen
Re: Twigils [ In reply to ]
There are two parts to this argument I haven't seen anyone else make
yet, so here in the hope that this isn't at all a repeat.

Also, both of these points are made by reference to myself having
actually written large amounts of real actual code using Object::Pad.
[1].


## Dynamic Method Generation

If twigil syntax exists, then methods that access slots can be
dynamically added to classes by MOP access, by way of a `:unbound`
method attribute. This tells the compiler *not* to resolve slot names
at the time the method body is compiled:

my $mref = method :unbound {
$:aslot++;
};

This "unbound method" is not yet useable, but can now be attached to a
class by a MOP call, and only at that point we'll resolve the slot name
in that class:

$metaclass->add_slot( '$:aslot' );
$metaclass->add_method( inc_slot => method :unbound { $:aslot++ } );

If instead, slot variables look identical to regular lexicals, then
code of this form cannot be constructed. There would be no way to write
the anonymous `method {}` reference in the first block of code above,
without it failing to parse at compiletime because of an unrecognised
variable name.

A mechanism does currently exist in Object::Pad to do this kind of
thing, and it is Not Pretty:

my $metaslot = $metaclass->add_slot( '$aslot' );
$metaclass->add_method( inc_slot => sub { # we can't use method
my $self = shift; # because we're not method
$metaslot->value($self)++;
});

It turns what would be a simple efficient OP_SLOTPAD inside the method
body into a closure capture of the $metaslot instance which invokes
an lvalue accessor method on it at runtime, just to fetch the value of
that slot. It works, but it's incredibly inefficient and removes most
of the entire point of having these slot variables feel variable-like
in the first place.


## Surprising Lazy Initialization

One of the commonly-requested features from Moo(se?) users is "does it
support lazy builders?". I have been hesitant to add these to
Object::Pad itself for the reasons I explain below, but because people
kept asking about it, I created a mechanism to allow 3rd-party
attributes, and then created this:

https://metacpan.org/pod/Object::Pad::SlotAttr::LazyInit

This kind of thing is subtle to use in practice, because "slots look
like lexicals". With Moo(se?), all instance data is accessed via
accessor methods, and people are culturally used to the fact that
methods can run code. They might print spurious warnings, or they might
fail outright:

use Moo;
package OrangePeeler;

has orange => ( is => 'lazy' );
sub _build_orange {
die "Not on a Tuesday, no" if (localtime)[6] == 2;
warn "Maybe, maybe not" if rand > 0.5;
return Orange->new;
}

sub peel {
my $self = shift;

# might die or warn but that's OK; we expect that
my $orange = $self->orange;
say "Peeling $orange...";
}

Whereas, if all your slot variables look just like variables, then this
might be considered surprising:

use Object::Pad;
class OrangePeeler;

has $orange :LazyInit(_make_orange);
method _make_orange {
die "Not on a Tuesday, no" if (localtime)[6] == 2;
warn "Maybe, maybe not" if rand > 0.5;
return Orange->new;
}

method peel {
# This variable interpolation itself might die or warn
say "Peeling $orange...";
}

By using a twigil and making slots "look different to variables", we
can disarm this false feeling of safety, by reminding the programmer
that these aren't just boring lexical variables, and that fun things
may still happen:

method peel {
# This interpolation might die, but that's OK because it looks weird
say "Peeling $:orange...";
}

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: Twigils [ In reply to ]
??, 12 ???. 2021 ?. ? 14:25, Ovid via perl5-porters <perl5-porters@perl.org>:
> Twigils is one way of solving that issue.

Nobody's asked yet, but what's the price? Is new parser hook enough,
or this would be a forever-binding code block that exists in core
solely to support a single CPAN module?

Best regards,
Sergey Aleynikov
Re: Twigils [ In reply to ]
On Fri, Aug 20, 2021 at 9:14 AM Sergey Aleynikov
<sergey.aleynikov@gmail.com> wrote:
>
> ??, 12 ???. 2021 ?. ? 14:25, Ovid via perl5-porters <perl5-porters@perl.org>:
> > Twigils is one way of solving that issue.
>
> Nobody's asked yet, but what's the price? Is new parser hook enough,
> or this would be a forever-binding code block that exists in core
> solely to support a single CPAN module?

This is not meant for Object::Pad, this is meant for an in-core
implementation of Corinna.

>
> Best regards,
> Sergey Aleynikov
Re: Twigils [ In reply to ]
??, 20 ???. 2021 ?. ? 11:44, Graham Knop <haarg@haarg.org>:
> This is not meant for Object::Pad, this is meant for an in-core
> implementation of Corinna.

I haven't heard that it's a done deal, and previous messages from Ovid
implied so. So, is it and p5p was unnotified?

Best regards,
Sergey Aleynikov
Re: Twigils [ In reply to ]
On Fri, Aug 20, 2021 at 12:37 PM Sergey Aleynikov
<sergey.aleynikov@gmail.com> wrote:
>
> ??, 20 ???. 2021 ?. ? 11:44, Graham Knop <haarg@haarg.org>:
> > This is not meant for Object::Pad, this is meant for an in-core
> > implementation of Corinna.
>
> I haven't heard that it's a done deal, and previous messages from Ovid
> implied so. So, is it and p5p was unnotified?

It isn't a done deal. That's why it's being discussed. This entire
thread is meant to help decide one part of what will go into the
Corinna RFC.

>
> Best regards,
> Sergey Aleynikov
Re: Twigils [ In reply to ]
On Friday, 20 August 2021, 14:21:59 CEST, Graham Knop <haarg@haarg.org> wrote:

> It isn't a done deal. That's why it's being discussed. This entire
> thread is meant to help decide one part of what will go into the
> Corinna RFC.
Just to be clear: ordinarily I wouldn't trouble P5P with trivial details about the RFC and I don't imagine doing so again. However, I know that some people are, um, so incredibly passionate about the twigil question that I just needed to quickly check on this issue.
I don't know which way we're going to go with twigils, but at least it doesn't look like a showstopper here.
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl
Re: Twigils [ In reply to ]
this would be a nice use case for a more robust macro language / source
rewriter. The twigils could get rewritten into valid miniperl. As well as a
lot of core features, for a general refactoring of the parsing steps.
Leading to "perl in perl" which AFAIK nobody has actually followed through
with.

On Fri, Aug 20, 2021 at 2:14 AM Sergey Aleynikov <sergey.aleynikov@gmail.com>
wrote:

> ??, 12 ???. 2021 ?. ? 14:25, Ovid via perl5-porters <
> perl5-porters@perl.org>:
> > Twigils is one way of solving that issue.
>
> Nobody's asked yet, but what's the price? Is new parser hook enough,
> or this would be a forever-binding code block that exists in core
> solely to support a single CPAN module?
>
> Best regards,
> Sergey Aleynikov
>


--
"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash
Re: Twigils [ In reply to ]
Re-ordered to avoid top posting.

> > ??, 12 ???. 2021 ?. ? 14:25, Ovid via perl5-porters <
> > perl5-porters@perl.org>:
> > > Twigils is one way of solving that issue.
> >
> > Nobody's asked yet, but what's the price? Is new parser hook enough,
> > or this would be a forever-binding code block that exists in core
> > solely to support a single CPAN module?

On Fri, Aug 20, 2021 at 10:25:09AM -0500, David Nicol wrote:
> this would be a nice use case for a more robust macro language / source
> rewriter. The twigils could get rewritten into valid miniperl. As well as a
> lot of core features, for a general refactoring of the parsing steps.
> Leading to "perl in perl" which AFAIK nobody has actually followed through
> with.

At first read your message seems on topic and reasonable.

But I keep thinking - THIS ADDS NO VALUE.

Hence my reply.

In that,

1) no-one has any good idea *how* to write a viable macro-language/source
re-writer
2) Saying "this would be a good use case for it" is true, but pointless if
we don't have one, or any route to one
3) repeatedly mentioning something as a "nice to have" doesn't change this.

Hence your reply is not useful, because it does not advance this discussion.
Or any discussion.


It doesn't add any value to this to say "This hypothetical other technology
that doesn't exist is a viable alternative to something we do have"


I'm asking you (and everyone, really) to stop mentioning concepts that don't
have any viable implementation. If we're proposing feature A, please stick
to insightful comments/observations for approaches that we can deliver it
using the technology that we have, rather than proposing feature B as a
prerequisite and hence a blocker.


(If you have some idea how to implement feature B, that's cool, but it
ought to be on a new thread.)


And as Neil and others have written previously, sending "harmless" mails is
not harmless - there is a cost to everyone else to read (or actively ignore)
mails sent to the list - "but you don't have to read my message" is *not* a
valid reason to continue writing off-topic messages.

Nicholas Clark
Re: Twigils [ In reply to ]
On 2021-08-20 8:25 a.m., David Nicol wrote:
> this would be a nice use case for a more robust macro language / source
> rewriter. The twigils could get rewritten into valid miniperl. As well as a lot
> of core features, for a general refactoring of the parsing steps. Leading to
> "perl in perl" which AFAIK nobody has actually followed through with.

The use of a source rewriter for this would imply that the proposed use of
Twigils is a short-hand for something else.

However, in this case the Twigils ARE the FUNDAMENTAL feature syntax, they are
the ONLY way to express what they are intended for, which is direct access to
slots, which are a new fundamental concept implemented in core and not
implemented over something that already exists.

(I had proposed that the Twigils could be a special short-hand for a more
general syntax that lets one reference slots of multiple objects directly from
the same context, however this idea was rejected for the Corinna MVP / v1.)

Therefore, it does not make sense to propose Twigils be immplemented using a
source rewriter.

-- Darren Duncan
Re: Twigils [ In reply to ]
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
Re: Twigils [ In reply to ]
On Fri, Aug 20, 2021 at 7:34 PM Darren Duncan <darren@darrenduncan.net>
wrote:

> On 2021-08-20 8:25 a.m., David Nicol wrote:
> > this would be a nice use case for a more robust macro language / source
> > rewriter. The twigils could get rewritten into valid miniperl. As well
> as a lot
> > of core features, for a general refactoring of the parsing steps.
> Leading to
> > "perl in perl" which AFAIK nobody has actually followed through with.
>
> The use of a source rewriter for this would imply that the proposed use of
> Twigils is a short-hand for something else.
>
> However, in this case the Twigils ARE the FUNDAMENTAL feature syntax, they
> are
> the ONLY way to express what they are intended for, which is direct access
> to
> slots, which are a new fundamental concept implemented in core and not
> implemented over something that already exists.
>

Except -- in the macro rewriting daydream, lots of other core syntax gets
rewritten too. Anyway, the suggested question appears to be, what would the
twigil expression get rewritten to?

Presuming every method starts by defining $context (whatever that is),
$.slot would get rewritten to something like

drumroll please

CORE::Corinna::twigil_access($context,'slot');

see what I mean?
Re: Twigils [ In reply to ]
On Monday, 30 August 2021, 13:59:51 CEST, Dave Mitchell <davem@iabyn.com> wrote:

On Thu, Aug 12, 2021 at 11:24:43AM +0000, Ovid via perl5-porters wrote:
> 1) Note I am not (yet) very familiar with Corinna.
When we eventually have the Corinna RFC ready, this will be an issue.
For those who want to know more (and especially for those of you who have veto access), I've written code to generate a table of contents and navigable RFC sections:
https://github.com/Ovid/Cor/blob/master/rfc/toc.md

The proposal is now much easier to both read and navigate. More features are forthcoming. The RFC generator, of course, is written in Object::Pad (https://github.com/Ovid/Cor/blob/master/lib/Corinna/RFC/Writer.pm) and the long-term goal is to convert it to Corinna, thus helping to dogfood our work. It's already proved to be enlightening.
Best,Ovid-- IT consulting, training, specializing in Perl, databases, and agile developmenthttp://www.allaroundtheworld.fr/. 
Buy my book! - http://bit.ly/beginning_perl