4 ms·
Would named positianal arguments with defaults not work in your scenario?
by jck 13y ago
Would named positianal arguments with defaults not work in your scenario?
- mtrn 13y agoI guess no. In my use case hundreds of keywords are possible and in the ideal scenario `f(a=1, b=2)` and `f(b=2, a=1)` could be distinguished and saved internally in the order they were given. There are easy ways around this, e.g. just passing something ordered to `f`, but the keyword argument syntax seems the most concise to me. Or maybe I do not get you approach - in that case, could you give an example?
- tome 13y agoHow about passing an ordered dict?
- pekk 13y agoEven if you figured out a way to do this, it's wrong wrong wrong. Everyone using an API has a natural and correct expectation that keyword arguments will be order-insensitive. Making them order-sensitive is just begging for trouble.
- Tehnix 13y agoIf they are, by default, order-insensitive, then it should pose no problem at all to make them order-sensitive, since you would not know what order they would appear in either way. Now, if you had said the other way around (ppl expect them to be order-sensitive but they are order-insensitive), that would have made sense...
- frobozz 13y agoNo. Because normal behaviour is order-insensitive, I expect that f(a=1,b=2) and f(b=2,a=1) should have identical behaviour. If you make the arguments order-sensitive, then they may not. If, for readability reasons, I change the order of the arguments, I will then be surprised when my code stops working. Conversely, If (because I think it is order-sensitive) I believe that, in order to make the function do what I want, I have to call f(a=1,b=2) and not f(b=2,a=1), then I'm not going to change the order willy-nilly, so I won't be affected by my expectations not matching reality.