Front page | perl.perl5.porters |
Postings from March 2023
Re: Pre-RFC Deep constants
Thread Previous
From:
Elvin Aslanov
Date:
March 9, 2023 18:57
Subject:
Re: Pre-RFC Deep constants
Message ID:
CAJ4KP=1gCcGOzYzOdfkK5B39bGoUK1_SZn5k_Cx9LKuGvf2_Rg@mail.gmail.com
On naming thereof I think:
my $variable :constant = 1;
is much more readable than "readonly" or "const".
It's not a keyword, so let's type it fully as an attribute.
On Thu, Mar 9, 2023 at 10:40â¯PM Ovid <curtis.poe@gmail.com> wrote:
> I think Perl needs constants in the core. The issue with blessed
> references (or Corinna objects), can be vexing, so I'll punt on that, but
> native constants are a needed feature and trying to choose from amongst the
> various CPAN modules isn't fun. If you just have scalars, some people
> (including me), still use sub foo() { 'frobnicate' }, but that's obscure
> if you don't understand what the empty prototype is doing there, or how the
> contents of the sub body impact behavior.
>
> On Thu, Mar 9, 2023 at 5:58â¯PM Robert Rothenberg <rrwo@cpan.org> wrote:
>
> 2. An attribute
>>
>> my $var :readonly = ....
>>
>
> I would vote for an attribute. The builtin:: namespace is there, in part,
> because Perl is already huge, and we're struggling to find ways to
> introduce new core behavior without breaking existing code. There are a few
> times new syntax has been proposed which conflict with punctuation
> variables, too. Perl's huge.
>
> Attributes are a way of adding new behavior which is less likely to
> conflict. However, I think attributes should *generally* be reserved for
> behavior which augments existing behavior. Using my $foo :constant = ...;,
> we're taking an existing language construct and augmenting this.
>
> I think this actually fits the linguistic nature of Perl. Think of
> attributes as adjectives modifying a noun. If something should be an
> adjective, making it an attribute is a clean way and mostly safe way of
> extending Perl.
>
> If we have a proliferation of attributes, that might be an issue, too, but
> if we think about the "noun" as a namespace, we could possibly reuse
> existing attributes. The :const attribute is defined as this:
>
> const
> This experimental attribute, introduced in Perl 5.22,
> only applies to anonymous subroutines. It causes
> the subroutine to be called as soon as the "sub"
> expression is evaluated. The return value is captured
> and turned into a constant subroutine.
>
> But saying my $foo :const = ...; is clearly using the "adjective" in a
> different context, so it can be evaluated differently. Whether or not this
> is something that's likely to be a source of confusion is something I'm
> unsure about.
>
> Best,
> Ovid
>
Thread Previous