develooper Front page | perl.perl5.porters | Postings from January 2017

Re: Should we consider locked hashes a failed experiment?

Thread Previous | Thread Next
Dave Mitchell
January 30, 2017 17:13
Re: Should we consider locked hashes a failed experiment?
Message ID:
On Sat, Jan 28, 2017 at 03:31:48PM +0100, demerphq wrote:
> My experience with locked hashes is that as currently implemented they
> are nearly useless.

Their main advantage (as exposed by 'use fields') is that they check,
at *compile* time, that you're not using an invalid key for an
object, which has always been a big elephant in the room as regards
Perl's idiosyncratic use of hashes as objects.

    package Foo;

    use fields qw(a b c);

    sub new { bless { qw(a 1 b 2 c 3) } }

    package main;

    my Foo $Fr = Foo->new();

    $Fr->{a} = 1; # ok
    $Fr->{d} = 1; # compile-time error

I'm not sure what checking is done at run time.

My feeling is that guarantees this functionality, so we need to
support it. If part of this functionality is provided by the HV API,
then if we implement HV vtables, it would make sense to implement fixed
hashes via a separate vtable and remove any such code from the general
HV code.

Lear: Dost thou call me fool, boy?
Fool: All thy other titles thou hast given away; that thou wast born with.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About