in reply to Re^7: next unless condition
in thread next unless condition
I'm curious, though... Could you name a couple of languages in which the order of operations is not guaranteed? I don't think I've ever seen one myself and I have a hard time imagining the practical use of having an indeterminate order of operations.
Besides FORTRAN, which hippo mentioned, C also doesn't guarantee order of evaluation
Update: Apparently, logical or (and, presumably logical and) does have its evaluation order specific in the C11 standard. (pointed out by Athanasius)
Not all programming languages allow the use of if or unless as statement modifiers, nor the use of else in that fashion. If using or for flow control is bad practice because it's not reliable in other languages, then surely the use of statement modifiers is just as bad.
There's a difference between "not reliable" and "not supported".
Proper evaluation of or doesn't require a particular order for evaluating its operands to get the correct result. This is because or is transitive. The compiler is free to evaluate the operands as is convenient. It could even turn the operand expressions into tasks that a multi-threaded CPU could execute in parallel.
Update: Correction: The proper term is "commutative", not "transitive". (thanks, Athanasius)
Statement modifiers are not transitive. They intrinsically require a particular order of evaluation. if, as a statement modifier, requires right-to-left evaluation of its operands to produce a correct result. An else modifier would require left-to-right evaluation. The compiler doesn't get to choose which order is more convenient.
While, in Perl, the intent of something or die; is reasonably clear, something or something_else; is not as clear. While it being in void context might imply intent, it could just as easily be a mistake.
something else something_else; would be unambiguous in its intent.
As a native speaker of English, I find "open or die" to be a vastly clearer statement of intent than "open else die".
The computer is not. And I would say that the "die" part of "or die" is what gives that its clarity. And while common use of English encourages left-to-right evaluation, "something_else or something" is a fully valid, English interpretation of "something or something_else".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: next unless condition
by Athanasius (Archbishop) on Apr 06, 2016 at 07:57 UTC | |
by oiskuu (Hermit) on Apr 06, 2016 at 22:19 UTC | |
by choroba (Cardinal) on Apr 06, 2016 at 22:44 UTC | |
by BrowserUk (Patriarch) on Apr 06, 2016 at 23:12 UTC |