-
-
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
Order of evaluation is (generally) not documented #49067
Comments
My guess is that order of evaluation for function arguments (note: not keyword arguments) remains unspecified for a simple reason: it is an anti-pattern to rely on argument evaluation order. Order is relevant only if the evaluation of arguments produces side effects, and the order said side effects is relevant. In such a case, one should use conventional control flow constructs (if needed), or simply break the arguments onto separate lines, thereby enforcing an evaluation which meets the need. Ideally, one should separate the side effects from the argument construction step altogether. As for rebuttals of the form "but it's clever..." -- consider yourself 6-12 months from now: will you remember all the weird things you packed into your code? not very likely. |
If it’s preferable to leave the order of evaluation for function arguments unspecified (like in C), that’s perfectly fine with me too. My point is that either way it should be documented what guarantees there are and aren’t, especially given the similar statement about chained comparisons in the documentation I pointed out. |
We are happy to specify it should be typically left to right of the parse tree result. But there are likely still some bugs |
I think it's fine to document it and then deal with bugs as they get reported. |
IIUC Fortress had undefined evaluation order and evaluated expressions in parallel. It could be cool to take advantage of that in Julia too. |
As the title says, there seems to be a lack of documentation around order of evaluation. Currently, the only times this comes up in the documentation are:
where
clauses is also related in some sense and is indeed documented.There was PR #24603 to document the order of evaluation for function arguments (which would probably cover most cases where this question might pop up), but that was closed without comment after almost 4 years? Is that simply a matter of someone finishing the work on that PR?
Also see the discussion here:
https://discourse.julialang.org/t/guarantees-on-order-of-evaluation/96259
The text was updated successfully, but these errors were encountered: