http://qs321.pair.com?node_id=161612


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.