Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Why get() and set() accessor methods are evil

by demerphq (Chancellor)
on Nov 27, 2003 at 00:34 UTC ( #310432=note: print w/replies, xml ) Need Help??


in reply to Why get() and set() accessor methods are evil

I found this whole thread interesting. When i read the title I thought "yep, I agree with that" but then on reading closer it wasnt even what I was thinking at all! :-) What I thought you meant was all those aweful sub like

sub get_foo { my $self=shift; return $self->{foo}; }

and its correspondingly ugly set_foo. If you had been talking about those being evil then i would agree. :-) Perl offers fancier and IMO more intuitive ways to do things:

sub foo { my $self=shift; if (@_) { $self->{foo}=shift; return $self; } else { return $self->{foo} } }

(or a variant thereof, you can golf it down nicely. :-)


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2021-01-23 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?