|
Lee Ludd
Scripted doors & windows
Join date: 16 May 2005
Posts: 243
|
03-24-2008 11:29
Old C programmers beware: According to K&E "Expressions connected by && or || are evaluated left to right, and it is guaranteed that evaluation will stop as soon as the truth or falsehood is known." LSL does NOT follow this convention. Expressions connect by || are apparently evaluated right to left, and all terms are evaluated, even if the right most term (say) is TRUE. This has implications for performance. If statement A is cheap and likely to be true, and statement B is expensive, a block like "if (A || B) { ... }" may be slower than "if (A) { ... } else if ( B) { ... }" even if it means coding the { ... } part twice or (probably better) replacing it with a subroutine call.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-24-2008 11:35
Yeah. Be especially wary of expressions with side effects (any kind of increment, decrement, or assignment operators). Generally it is good programming practice to separate such side effects from logical expression evaluation anyway, but there are a lot who don't follow such practices (and there are also a few things like memory/speed optimization that tend to discourage them in LSL).
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-24-2008 15:13
one of the things I truly miss in LSL, the lack of short circuiting, which introduces extra needless if's and more byte code.... anyone checked mono to see if it obeys the short circuit convention?
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-24-2008 15:57
Yes. Mono is the same, or was a version or two ago anyway. I doubt that's something they've changed since. They want the language to behave as much the same as possible.
|