Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: •Re: Re: •Re: On goto

by djantzen (Priest)
on Mar 01, 2003 at 06:23 UTC ( #239669=note: print w/replies, xml ) Need Help??

in reply to •Re: Re: •Re: On goto
in thread On goto

What are your thoughts on using it in constructors of hash or array based objects for purposes of clarity?

For example:

sub new { my ($class) = @_; my $this = bless {}, $class; $this->{foo} = undef; $this->{bar} = undef; return $this; }

Where 'foo' and 'bar' may be initialized during the course of the program, but not at construction. To me, this makes it more clear what an instance of this class consists of. It also can make debugging easier if you are fond of Data::Dumpering as I am.

"The dead do not recognize context" -- Kai, Lexx

Replies are listed 'Best First'.
•Re: Re: •Re: Re: •Re: On goto
by merlyn (Sage) on Mar 01, 2003 at 06:32 UTC
    That seems to be more than a simple declaration, and the semantics would obviously change if you eliminated that line. I don't consider that an equivalent to my "no = undef" principle.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Re: •Re: Re: •Re: On goto
by Anonymous Monk on Mar 01, 2003 at 16:04 UTC
    I prefer:
    sub new { bless { foo => undef, bar => undef, }, shift; }
    That may be golfing it too far for your tastes, but the point is still valid. Creating the data structure with the data you want already in it is generally clearer than creating it and then building it up with fixed assignments.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://239669]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2018-04-22 23:12 GMT
Find Nodes?
    Voting Booth?