On 28 January 2017 at 16:13, James E Keenan <jkeen@verizon.net> wrote: > On 01/28/2017 09:31 AM, demerphq wrote: >> >> My experience with locked hashes is that as currently implemented they >> are nearly useless. A simple read of a non-existent key becomes a >> fatal exception, which makes them nearly unusable in conventional >> code. At work we have tried to use them for a few purposes, and >> generally it is has been a failure. They impose a run time penalty on >> all hash access even though they are barely used. >> >> As far as I can tell locked hashes were invented as a way to work >> around our lack of core support for true objects/structs. > > > Let's have some research to see if that was indeed the rational for this > feature. > >> (Where >> accessing a non-existent member *should* throw an exception, but >> preferably a compile time one.) However with perls standard object >> model and usage patterns I have never really seen anyone use them this >> way. >> >> Steffen has started working on a patch series to make hashes >> pluggable. (Big big fricking A to him on that!) This is only going to >> be more complex if we support locking (does every hash implementation >> have to support locking? Does the hash api have to support >> "clear_placeholders"? >> >> I propose that we get rid of locked hashes. I have written tons of >> code to help support them, and I consider them a total failed >> experiment. >> >> Also, use of clear_placeholders and related functionality is one of >> the "hidden apis" which we have in Internals that really has no >> business being exposed to end users. >> >> Once we have a pluggable API for hashes, we can implement lockable >> hashes using them and if people really want them we can provide them. >> >> What do people think? Should every hash access and store pay a penalty >> for locked hashes when they are almost unused? >> > > Before we do anything else, we should grep CPAN to estimate the frequency of > their use. > > I'd also recommend that organizations that have a big investment in Perl > and/or a large Perl codebase conduct the same search. I can speak for Booking.com, we have exactly two uses in gazillions of lines of code. Neither is particular important, and can be removed or implemented a different way. > For reference (as I had to do this to remember what locked hashes were): The other term for locked hashes is "restricted hash", which is generally documented in Hash::Util. cheers, Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"Thread Previous