Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: "Fields" for "Objects"

by whakka (Hermit)
on Jun 11, 2009 at 00:09 UTC ( #770473=note: print w/ replies, xml ) Need Help??


in reply to Re: "Fields" for "Objects"
in thread "Fields" for "Objects"

It's interesting, this is how I write them too. But I noticed lodin's node, which contains an important but subtle difference; by doing this:

sub field { my $self = shift; $self->{field} = $_[0] if @_; ... }
instead of this:
sub field { my ($self,$val) = @_; $self->{field} = $val if defined $val; ... }
you don't run into issues where $self->field(undef) would silently return the old value without changing it, which isn't what you might expect. But because I've seen the second form elsewhere and it's technically better practice to assign @_ to variables I just stuck with it, but clearly the first way is better.


Comment on Re^2: "Fields" for "Objects"
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://770473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-08-31 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls