-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
official conventional argument precedence #19150
Comments
E.g. #18931 (comment) |
Related topic: should mutated arguments for |
Part of #20402. |
I propose the following priority order (highest priority listed first):
Exception: first argument to This is an interesting case:
I think |
Using keyword args for |
👍 With regards to the position of "things being mutated," one of the patterns I seem to fall into in my own code is a separation between outputs and caches/temporary workspace arguments; I tend to put outputs near the front but workspace variables towards the end. I'm not recommending this specific approach, but I bring it up in case the distinction is worth considering. |
I think that's a fairly common distinction, @timholy – I believe that it comes from C APIs. I read about this recently, and can try to find a reference to it. |
Regarding Jeff' comment above, this feels like a really principled ordering which would be pretty confusing to new and mid-level users like me. Roughly, when I'm trying to remember the order of function arguments, I'm not thinking about IOStreams and Types and Collections: I'm thinking about required and optional arguments. And understandably, the current language is pretty inconsistent about whether optional arguments go first, last, or some combination thereof. Maybe that just means new users need to change their thinking - and it has e.g. become natural to think of functions going first for do blocks. |
|
Would One could directly address this with a caveat saying "When one of these is varargs it can be moved to last place" |
Is parse the same exception like convert? For me the (optional) type argument on 2nd place would be more natural. |
We have a number of conventions about first arguments: functions, I/O objects, types (others?). We should document these conventions explicitly and assign them an official precedence since otherwise when there are conflicts, people tend to simply pick a random order.
#16307 (finalizer argument order)
The text was updated successfully, but these errors were encountered: