Skip to content
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

Open
Socob opened this issue Mar 20, 2023 · 5 comments
Open

Order of evaluation is (generally) not documented #49067

Socob opened this issue Mar 20, 2023 · 5 comments

Comments

@Socob
Copy link
Contributor

Socob commented Mar 20, 2023

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:

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

@andrewjradcliffe
Copy link
Contributor

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.

@Socob
Copy link
Contributor Author

Socob commented Mar 24, 2023

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.

@vtjnash
Copy link
Member

vtjnash commented Mar 24, 2023

We are happy to specify it should be typically left to right of the parse tree result. But there are likely still some bugs

@StefanKarpinski
Copy link
Member

I think it's fine to document it and then deal with bugs as they get reported.

@jariji
Copy link
Contributor

jariji commented Apr 12, 2023

IIUC Fortress had undefined evaluation order and evaluated expressions in parallel. It could be cool to take advantage of that in Julia too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants