Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Correct idiom for default parameters

by mrider (Sexton)
on Apr 28, 2010 at 18:12 UTC ( #837365=note: print w/ replies, xml ) Need Help??


in reply to Re: Correct idiom for default parameters
in thread Correct idiom for default parameters

Thanks for that, although that doesn't quite do what I'm hoping. I'm not necessarily looking for named parameters, and it makes calling the code more difficult than I wanted.


Comment on Re^2: Correct idiom for default parameters
Re^3: Correct idiom for default parameters
by Your Mother (Canon) on Apr 28, 2010 at 18:31 UTC

    It also makes the calling code self-documenting. This is a large win for anyone dealing with the code including you when you come back to it a couple months later and can't remember which of the 6 args goes in the middle or what happens if you leave arg 2 out, etc, etc.

      Maybe, maybe not. Sometimes, it's rather obvious what the arguments are. Sometimes, all the arguments play the same role. And sometimes, it would be just bloody annoying to use named parameters all the time. Do you really want to write:
      my $substr = substr(subject => $str, first_char => 5, length => 3, + replacement => "bar"); my @parts = split(subject => $str, pattern => qr/foo/, max_parts = +> 7, keep_trailing_empty_fields => 1);
      ? I'm not sure whether it's more readable. Or whether it's harder to remember that a negative third argument to split indicates trailing empty fields should be preserved than it is to remember the name of the flag.

        Completely agree. Of course built-ins are special and functions unlike object constructors have a higher tolerance for inlining things because they never get examined/reused/reset by name.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-08-02 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (54 votes), past polls