4 ms·
a way to avoid this in python that i quite like is to require keyword arguments: def foo(*, x, y): pass # you must do this foo(x=5, y=6) # yo
by hprotagonist 7y ago
a way to avoid this in python that i quite like is to require keyword arguments:
def foo(*, x, y):
pass
# you must do this
foo(x=5, y=6)
# you cannot do this
foo(5,6)
# and therefore you also may not
foo(6,5)
This is a little autocratic but the other nice thing is that if you’re finding it really painful to use it means you should probably refactor anyway.
- XJ6 7y agoI prefer to let the IDE do this. Developing C# in rider if you call `foo(a,b)` then it'll display as `foo(from: a, to: b)` in the IDE.
- throwaway744678 7y agoAll Jetbrains IDE do this (AFAIK). One can even configure the cases when these are displayed (ie. only show the hints when there is an ambiguity)
- hprotagonist 7y agofor my own uses, that's great. I write my libraries like this because i want to beat my users into being explicit -- thus the "a little autocratic, but.." caveat.