Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: named arguments

by dws (Chancellor)
on Nov 21, 2004 at 07:51 UTC ( [id://409340]=note: print w/replies, xml ) Need Help??


in reply to named arguments

1. Where is the line, for you, between "need named arguments" and "don't need named arguments" ? 2 args ? 4 ? 27 ?

For me it's less a matter of number than it is about how the arguments will be used. If they'll be used to add to or override someone else's values, then named args are the way to go. This lets me write, for one contrived example,

sub foo { my ($self, %args) = @_; $self->bar( answer => 42, %args, );
This lets foo have a dialog with bar that involves some overridable default behavior. A more common form of this is default constructor state.
sub new { my ($class, %args) = @_; return bless { loglevel => 0, die_randomly => 0, %args, }, $class; }
Here, the constructor provides default state that clients can override. Easy to do with named arguments; difficult to impossible with positional args.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found