Re: [xsl] Is the semantics of the "or" operator implementation-dependent?

Subject: Re: [xsl] Is the semantics of the "or" operator implementation-dependent?
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 16 Sep 2014 15:53:12 -0000
>> No, the semantics not, the order of execution is, however, which means that
in error-cases, you can have different outcomes between processors. This is
not different from other languages, in C#, F#, Java, C++ similar forms of
optimization exist.

> Considering B'15.7 in the Java Language Specification: Do you have an actual
example/experience of some Java expression (logical "or") where different
outcomes between processors have been observed?

Note that I said "similar forms". I checked, and I think that all mentioned
languages do left-to-right short-circuitring only (didn't know, but apparently
this is also known as  McCarthy evaluation), which allows code like this,
which is deterministic:

if(a != 0 && b / a > 1) { return "larger than one division;" }
if(ptr && ptr->fileExists()) { return "file exists"; }

But, a better comparison would be with SQL, which does the same as XPath. In
fact, a user summarizes the order of evaluation for SQL in boolean expressions
as

"It does when it feels like it, but not in the way you immediately think of."

See:
http://dba.stackexchange.com/questions/5333/logical-operators-or-and-in-condi
tion-and-order-of-conditions-in-where, where the user also explains the main
reason (which Michael Kay already mentioned):

"We as developers have to be aware that SQL Server works differently. It is a
cost based system. To get the optimal execution plan for our query the query
processor has to evaluate every where condition and assign it a cost. "

Which can just as well be recast with XPath (or XQuery and XSLT by extension,
where order of evaluation is undefined, not only for boolean expressions):

"We as developers have to be aware that XPath works differently. It is a cost
based system. To get the optimal execution plan for our XPath query the
processor has to evaluate the conditions everywhere and assign it a cost. "

Cheers,

Abel Braaksma
Exselt XSLT 3.0 streaming processor
http://exselt.net

Current Thread