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

Re: [perl #5087] used only once warning

Thread Previous | Thread Next
From:
Abigail
Date:
January 21, 2018 20:26
Subject:
Re: [perl #5087] used only once warning
Message ID:
20180121203025.GA3512@almanda.fritz.box
On Sat, Jan 20, 2018 at 09:29:42PM +0100, Sawyer X wrote:
> On 01/19/2018 11:24 PM, Abigail via RT wrote:
> >
> > But declaring variables, and never using them can still be very useful.
> >
> > This is how I write new() in my objects:
> >
> >     sub new ($class) {
> >         bless \do {my $var} => $class;  #  Or bless do {\my $var} => $class
> >     }
> 
> Out of curiosity, what's the benefit of this?


Because all I need of an object is its memory address. "Data inheritance
by default" is, IMO, an extremely lousy way of writing maintainable
programs. So is using hash keys as variables (why bother with strict
if you do so?)

Hence, I don't do that. Instead, I store the objects attributes in lexical
hashes, using the memory address of the object as key. Fieldhashes take
care threads (where the memory address may change) and will clean up
if an object goes out of scope.



Abigail

Thread Previous | Thread Next


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