If the execution order is undefined, the execution may happen in parallel. Considering the rise of the multi-CPU machines, there can be a nice performance gain by not defining execution order.

Funnily enough, that is exactly where my thoughts on the subject started. I was thinking about the parallelisation of code using threads.

However, I would counter contend that if execution order is undefined and a compound statement could be transparently threaded, then, given the non-determanistic nature of threading, it would not only be impossible to guess the outcome of a compound statement--it would vary from run to run!

Indeed, if autothreading (in the threads sense rather than the P6 sense (if they are not the same thing?)), is ever going to be possible, it would be necessary to define the order of execution if the outcome of a compound statement is ever going to be predictable.

IMO, the less code relies on execution order, the clearer the code is.

Were it written down exactly when evaluation order could affect the outcome of a statement, then it would be easy to avoid it--but it isn't.

Unless you're advocating never using compound statements?

In which case, you would have to remove autoincrement, autodecrement and all the <op>= compound assignment operators from the language.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?

In reply to Re^4: Why is the execution order of subexpressions undefined? by BrowserUk
in thread Why is the execution order of subexpressions undefined? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.