Strict left-to-right *order* of comparisons [chaining] considered harmful [by me]

If you know that a part of a chained comparison in your own code might be expensive, then just manually arrange the control flow to avoid calling it if possible. This is everyday programming.

If you know how to implement this optimization in general — without slowing down any of the more mundane cases — then great! It wouldn’t even require a change to the documentation. As you note, the order of evaluation isn’t defined.

The current behavior is hardly harmful. Please respect the sensibilities of users and developers alike; posts like this aren’t productive.

2 Likes