In Python the options "object" is a dictionary.
Dictionaries are how named parameters are implemented in Python:
> But I am curious about the circumstances where having this ability
> would be of benefit. Are there calls where you feel this ability would
> be more clear or desired?
Yes. Named parameters let you rearrange/add/remove fields without
needing to go and change every caller. It also allows you to have
default values. Adding a positional argument requires you to change
every caller. It is very common to write methods that have both
positional (required) arguments as well as named (optional) arguments.
> The potential for collision in this situation is very high, and there
> would need to be very clear rules about how the values should settled
> before performing the call.
I think the rules used by Python are very clear. Python complains
loudly when *args and **kwargs map to the same variable and I imagine
that such behavior is outside the realm of the spec. The spec could
require that implementations generate an error whenever there is an
ambiguity.
--
David
What about C++, Java, C#, Javascript ?
=> no kwargs
=> mapping to ordered args
=> clash !
Again, json-rpc is a protocol, thus an effort toward aim not a simple
facility :)
Lo.
Thanks Lo. Is there any way these can be rectified?
These languages require a mapping to ordered arguments.
How do they handle by-name arguments right now?
Would it work if the rule was that "params": [...] must come first and
"options": {} afterwards? Can this rule apply to these languages?
"no kwargs" and "mapping to ordered args" - the above rule could work
for these concerns
"clash!" - I'm not sure what can be done about this aside from saying
"don't do that". Is it a show-stopper?
Thanks for your help,
--
David
They don't.
> Would it work if the rule was ...
Fact is that on one side there is a rule that says "you can do both but
not at the same time" and on the other a rule that would weight as much
as the rest of the spec to sort out all the exceptions etc .. just for a
feature that is a freak actually (IMHO).
> Now imagine what happens when the def gets changed to look like this:
>
> def sort(str_list, with_frobinator=False, case_insensitive=True):
> ...
The real question is why in the hell would you map it another way than :
{"jsonrpc": "2.0",
"id": 1,
"method": "sort",
"params": {
"str_list" : ["apple", "Apple", "banana"],
"with_frobinator" : false,
"case_insensitive" : true
}
}
> "clash!" - I'm not sure what can be done about this aside from saying
> "don't do that".
Btw : real programmers use tables ;P
Lo.