Page 2 of 2

Posted: Thu Jul 01, 2004 2:43 pm
by matthew180
tinman wrote:Just that short circuit evaluation in itself isn't a bug or problem, but it does seem to be broken at the moment.

Broken how? It's working fine for me and worked as expected in the little test app I wrote.

Please explaine how it is not working. Also, is short-circuiting something that Fred is only considering? My vote is to keep it, especially since PB already has it and changing to non-short-circuiting would break a lot of code (at least for me it would.)

Thanks,
Matthew

Posted: Thu Jul 01, 2004 3:49 pm
by tinman
matthew180 wrote:
tinman wrote:Just that short circuit evaluation in itself isn't a bug or problem, but it does seem to be broken at the moment.

Broken how? It's working fine for me and worked as expected in the little test app I wrote.

Please explaine how it is not working.
Dare2 or Kale (sorry guys, I fogot) posted a thread about combining logical operators. The short circuit evaluation misses out the entire line, ignoring things it shouldn't. I can't remember which forum it was in though and can't be bothered looking for it :)
Also, is short-circuiting something that Fred is only considering? My vote is to keep it, especially since PB already has it and changing to non-short-circuiting would break a lot of code (at least for me it would.)
It's there and AFAIK (for what it's worth) it's staying.

Posted: Wed Jul 14, 2004 4:40 pm
by guido
tinman wrote: Short circuit evaluation is a good thing. It means you don't need to evaluate both sides of a logical expression to get the result. Therefore if you have a simple comparison logically combined with an evil complex one, you're best putting the simple one on the left because it may mean you can avoid carrying out the right hand side thus saving you time.
For some background look here.
I see it a little differently. The most important thing is to know, whether it happens or not unconditionally, or whether it can be controlled by a compiler switch (as in good old Turbo Pascal). Many compilers activate it in in higher optimisation levels only.

In the time of simple CPUs it was a classical time/space trade off: querying the boolean intermediate result and jumping out of the comparison chain, if the result can't depend on terms to follow, adds some opcodes and saves some time. In time of more advanced CPUs jumping flushed the prefetch queues, so it was not paying off always for short jumps (therefore ARM conditional execution). Now with branch prediction and caches it again may pay off, but its difficult to judge without benchmark.

Summary: Short circuiting saves execution time, if there are MANY terms or if some of the terms are time-consuming functions. It leads to grey hairs, if one of the functions has a side effect leading to sporadic errors. Even if not supported by the compiler, it can be substituted by explicit coding.