r/ProgrammingLanguages • • Apr 10 '26

Borrow-checking surprises

https://www.scattered-thoughts.net/writing/borrow-checking-surprises
52 Upvotes

27 comments sorted by

View all comments

Show parent comment

5

u/iBPsThrowingObject Apr 10 '26

Did we need right-to-left evaluation all along? Was GCC right?

My feeling is that defining argument evaluation order is altogether a mistake. It should at most be opt-in, like repr(C) for field ordering.
I've never really tried to poke holes in this idea, there probably are downsides, but it feels like giving the compiler more flexibility to "just do what I mean" would be good.

8

u/Uncaffeinated 1subml, polysubml, cubiml Apr 11 '26

I disagree. Using non-standard evaluation order is going to lead to very confusing behavior. Even if you don't promise it, users will still assume left-to-right evaluation, and get mad when it doesn't happen.

6

u/Huge-Albatross9284 Apr 11 '26 edited Apr 11 '26

If you don't define argument evaluation order, you must either randomize it at runtime or make programs with observable differences from eval order impossible to write.

Otherwise, programs will inevitably implicitly depend on the concrete evaluation order your compiler actually uses in practice.

You can see a version of this idea in how Go goes out of it's way to randomize map iteration order, to prevent reliance on behavior (consistent map ordering) that the language doesn't always provide. Actually, Rust does the same with a seed per HashMap instance.

If you don't, the de-facto implementation of the unspecified behavior eventually get's codified into the spec: Python dicts, JS object fields, probably some others.