5 ms·
> You can easily get the same functionality with a single associative array config parameter. Not really, you lose most of the validation and documentation, yo
by masklinn 14y ago
> You can easily get the same functionality with a single associative array config parameter.
Not really, you lose most of the validation and documentation, you get 2 levels of parameters (first-class positionals and second-class keywords), you may not correctly detect or handle redundant provisions, defaults may or may not work the same way (and correctly), and it's not possible to provide through keywords a parameter the function's implementer has defined as positional, even if that's clearer for the callsite.
It works-ish, but it is and remains a hack and a pale shadow of first-class keyword parameters.
On the other hand, I can get behind the inverse: keyword-only parameters and positionals by abusing arrays (à la Smalltalk, Self or Objective-C), in my experience that significantly increases the code's readability and flexibility. Though it hardly plays nicely with partial application.
> That also has the additional benefit that the user of a function can reuse the config array
parameter packing & unpacking takes care of that, it's not an advantage of "a single associative array".
> the amount of boilerplate you save by making named parameters first class is tiny
To get the same functionality as e.g. Python's kwargs, we're probably talking about half a dozen lines. In each function. That's not tiny.
- wdewind 14y agoWhat? The benefit is not saved lines, it's ease of expressing explicitness (ie: inline with the function call instead of throw assigning to variables above it). Please show an example of how this is saving lines in a way that's not comprable to simply doing multiple assigns on one line (ie: destroying readability).
- masklinn 14y ago> What? The benefit is not saved lines Not sure what you're talking about. When somebody talks about "boilerplate", it's very much about the number of (setup/redundant) expressions/tokens having to be used to do something. > Please show an example of how this is saving lines in a way that's not comprable to simply doing multiple assigns on one line (ie: destroying readability). I would suggest actually reading my comment, that may give you a hint as to what I'm comparing and let you understand on your own how different it is.
- deleted 14y ago[deleted]
- ericingram 14y ago> Not really, you lose most of the validation and documentation... This is only true if you don't replace these forms of documentation with something better, which I'd do.
- masklinn 14y ago* Validation is not documentation, either it's there or it's not there, with built-in keyword arguments it's there, with a hash-hack it probably isn't. * Documenting a hash-hack will still require spelling out that one of the positional parameters is a hash, then diving into that hash to spell out the various keys. This adds one worthless level of indirections to first-class keyword parameters, which can just treat all parameters the same way for documentary purposes.