So, that leaves everyone, having written their expression, in the situation of having to guess whether it contains an EOD or not.Yes. So, don't do that. If you write an expression whose outcome doesn't depend on the order of evaluation, there's no guesswork required.
And no, there's no "comprehensive list". There's no "comprehensive list" of real numbers either. But it's easy to describe when an expression has an order of evaluation dependency: whenever an expression has 2 (or more) subexpressions in which it matters which subexpression is evaluated first has a dependency of order of evaluation. If you don't know whether it matters, and the order isn't defined for your construct (typically, an operator), avoid it.
I'd say, avoid writing things like $_[shift] = $_[shift]. Even if you know what the order of evaluation is, the maintainance programmer coming after you (or the guy willing to send you a patch) may not, and he needs to guess. If you write it as: my $i1 = shift; my $i2 = shift; $_[$i1] = $_[$i2], there's no guesswork involved to know what is happening. In the final expression, it doesn't matter whether $i1 gets fetched before $i2, or that the value of $_[$i2] gets fetched before or after the address of $_[$i1].
Any code that depends on the order of evaluation in expressions potentially leaves doubt with the reader, and, IMO, should be avoided. For the same reason you should avoid precedence doubt (use parens) - even while precedence order is defined.
I am calling you on that implication and asking you to demonstrate your superiour knowledge by showing me, and everyone else all the situations in which an EOD can arise in Perl.Ah, I see you haven't finished reading your own thread yet! Let me quote myself:
Does that print 13 or 12? Well, that depends on the order of evaluation of +. It prints 13 if the left hand side of + is evaluated before the right hand side, and 12 if the right hand side is evaluated before the left hand side. I say, avoid the situation. Perl doesn't define what the order is (no, the fact that it's deterministic doesn't mean it's defined. Just look at what has happened with hash keys), and I doubt there are any regression tests for it.my $i = 1; sub f {$i += 1; $_[0] * $i} print f(2) + f(3);
You won't attempt the former because it will show your superior knowledge to be nothing more than a superiour attitude, and reenforce my statement that your rhetoric is hollow and therefore meaningless.Perhaps you should....
You really should try arguing the subject instead of the man.
In reply to Re^11: Why is the execution order of subexpressions undefined?
by Anonymous Monk
in thread Why is the execution order of subexpressions undefined?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |