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

Re: [Ovid/Cor] To Twigil or Not To Twigil (#29)

From:
David Nicol
Date:
August 13, 2021 20:28
Subject:
Re: [Ovid/Cor] To Twigil or Not To Twigil (#29)
Message ID:
CAFwScO-mp-ssz0HNQDH9nGCYPqPoGGRKvSOJsZBuiXt2tXEG_w@mail.gmail.com
For what it's worth, I'd like to retract my suggestion of using (or,
implicitly suggested, enforcing) a leading underscore naming convention,
and replace that with a more compatible convention of always giving slots
L-value methods.

I often do that in my perl classes, so if that becomes how Corinna does it,
Corinna could become a set of standards that can be complied with -- one
could duck-type any old class into Corinna compatibility -- instead of a
hard interoperability boundary, that there will be a penalty for
interoperation between Corinna and non-Corinna types.

Hashref object implemention-specific slot access:   $obj->{field1} = 27;
Implementation-agnostic method-based slot access:  $object->field1 = 27;

This is what I'm talking about, l-value slot accessors:

set up the field1 method in an array-based class:

    sub field1 :lvalue { $_[0]->[5] } # assuming the index of field1 is 5

set up the field1 method in a hash-based class:

    sub field1 :lvalue { $_[0]->{field1} } # duh

set up the field1 method in an inside-out object (as I understand them,
which is barely, and possibly wrong):

    sub field1 :lvalue { no strict refs; ${"${$_[0]}::field1"} }  # object
is a reference to a scalar containing a unique package name, it isn't clear
to me what is gained by this approach

With L-value slot-accessor methods, the code that uses the class doesn't
need to know about the object's implementation to access the slots.

So do it that way.

Hmm -- I wonder how the proposed "defer" stuff interacts with :lvalue
routines. Can it be used to create on-modification magic?



On Thu, Aug 12, 2021 at 5:13 PM Graham Knop <notifications@github.com>
wrote:

> I agree with @davidnicol <https://github.com/davidnicol>, specially since
> :param already removes leading underscores.
>
> --
"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About