Why is a hyphen often used as the first character in named parameters?
Historically, because it allowed getopts to be used to parse/validate sub args?
And do the 'good reasons' (if any exist) outweigh the inconvenience of defeating part of the usefulness of the fat comma operator?
No. (Because there are no good reasons.)
Additionally, the justifictions for named parameters are overstated.
Is is debug or <c>-debug or Debug or DEBUG or -Debug or debug_on or debugOn or -debug_on or -DebugOn or DebugOn or ...
And on historical evidence, 7 out of ten times you will be wrong.
Programmers have been, are, and likely always will be notoriously bad at naming variables. There is no reason to believe they'll be any better at naming parameters.
First, you construct a list; then you construct a hash from that list; then you have to destructively decompose the hash in order that you can verify that the caller didn't misspell one or more parameters. Because if you don't check for typos, as many modules do not, then you silently adopt defaults for parameters that the programmer thought he had specified.
(NB: And all of that is before, and in addition to, validating the actual parameters themselves.)
"Performance doesn't matter" many will claim. But for the short, frequently-called methods that typify OO code, all those little bits add up.
And "Programmer efficiency is more important than program efficiency". But remind yourself of that the next time you spend days trying to track down a bug because you supplied the right value with a minor misspelling of a an unchecked parameter name.
In reply to Re: How should named paramater keys be named?
by BrowserUk
in thread How should named paramater keys be named?
by davido
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |