Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Shift versus Sanity

by drewbie (Chaplain)
on Apr 24, 2002 at 14:14 UTC ( [id://161612]=note: print w/replies, xml ) Need Help??


in reply to Re: Shift versus Sanity
in thread Shift versus Sanity

# Bad sub bar { my $self = shift; my %options = @_; }
I have to disagree with you on this one, sort of. I use this construct to set defaults to named parameters like this:
sub bar { my $self = shift; my %options = (opt1=>'foo', # desc for opt1 opt2=>'bar', # desc for opt2 @_); }
To me, this is the best of both worlds. I get an obvious object ($self), I know what my expected named arguments are, their default values, and a brief description of each parameter. Yes, it's slightly more memory intensive, but it's so much more intuitive to me that I'll take the tradeoff anyday.

As someone else said, I'll take maintainability over a little verboseness & overhead anyday. Being able to figure out what the heck a rarely used option does is invaluable 4 months (or years!) down the road.

Replies are listed 'Best First'.
Re: Re: Re: Shift versus Sanity
by Juerd (Abbot) on Apr 24, 2002 at 17:34 UTC

    I use this construct to set defaults to named parameters like this

    Oops, forgot about that idiom. Yes, when using to set defaults, it is okay :)

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (9)
As of 2024-03-28 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found