User talk:Dinosaur: Difference between revisions

Line 61:
::The example code at the head of the article relies on short-circuit evaluation without mention (even though the Wikipaedia article does warn on this) and many of the examples in the various languages also appear to rely on partial evaluation too, without remark, matching the example code, or not matching it, without remark. This may be correct, if short-circuit evaluation is the style for that language, or it may be incorrect. The correctness you praise then relies on the unmentioned details of a particular language, unknown to non-users of the language, and probably not in the front of the consciousness of the author either. Put another way, the same algorithm would succeed or fail in various languages, depending not on the source code, but on the choice of a recondite detail of the language's implementation that may or may not be specified in one standard or another that a particular compiler/interpreter/programmer may or may not follow. The original author did after all test their version and found that it worked. There are innumerable programmes that have worked when checked, and worked throughout their use (apparently), and when transferred to a different compiler, fail. I suppose there is "correct" (the damn thing works) and "Correct", the latter being so for code that will work for all variants of a compiler - correct compilers only, of course. But for complex programmes, "Correct" is a numinous state and unattainable, since over time the language standard is revised to mention newly-discovered ambiguities, or, change their interpretation. As a historical example, the DO-loop interpretation in early Fortran always executed at least once, since the test was made at the end of the loop - and in those days there was no separate standard as such, what the specific compiler did ruled. For most loops this saved a test, and sometimes it was desired behaviour in certain situations (such as this one!) though not in others, and the latter choice became the approved way. Without change to the code, a correct prog. becomes incorrect through change to an entirely separate item. Unfair!
::But yes, I'll admit that I think that short-circuit evaluation is correct, and that code that works with that is correct (especially when it is tested and works correctly), and that the order of evaluation of expressions is fully defined (tie-breaker rule: left-to-right for equal precedence), and I resist the more recent Fortran specifications whereby, maddeningly, it is specified that this is not specified. Because I think that is incorrect... Time for a drink. Cheers, [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 02:26, 31 December 2017 (UTC)
:::There is already a task about '''[[Short-circuit evaluation]]'''. You are free to read it, or not, but do not claim you are left alone in a fog. Anyway, the standard has not changed much since the 1978 flavor: "It is not necessary for a processor to evaluate all of the operands of an expression if the value of the expression can be determined otherwise." (Fortran 77, section 6-20). It is permitted, but not mandatory, hence you can't count on it. Anyway, the order of evaluation is not guaranteed either. A program that relies on short-circuit evaluation is not standard conformant, and it has never been. A compiler may provide such a feature ''and document it'', but I know no example. Have a look at [https://gcc.gnu.org/ml/fortran/2007-03/msg00368.html this] for gfortran, for instance. Now, you are free to write buggy code which happens to work sometimes, you may even be proud of it. Who cares? [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 13:37, 31 December 2017 (UTC)
1,336

edits