#79399 - 2003-01-08 11:59 PM
Re: iif() stack overflow exception "problem"?
|
Lee Wilmott
Starting to like KiXtart
Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
|
The If ... Else ... statement may well be quicker; I was just thinking (maybe that's the problem) that my exp() function would be a good test for the new iif() function.
You know what it is like, a new function is introduced to KiX - you've gotta have a look, haven't you?!?!?
Like you Shawn, I would only use iif() for the more simplistic task. However, the reason for posting my original post is that I thought that the returned result was incorrect and that it may have bigger, more important consequences.
I must admit, I'm not sure that after reading your comments that this is any clearer for me!!!
I agree with you Shawn, the iif() function is merely...
code:
Function IIF($x,$y,$z) If $x $IIF=$y Else $IIF=$z EndIf EndFunction
But seeing as this is all my exp() function contains is the if ... else ... statement, so why can't this statement be replaced with iif()?
Although, I believe you are correct; logically speaking this is exactly what iif() does, however programatically I would have to argue that it is different!
Am I missing something?
Lee
|
Top
|
|
|
|
#79401 - 2003-01-09 09:39 AM
Re: iif() stack overflow exception "problem"?
|
Lee Wilmott
Starting to like KiXtart
Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
|
I'm with you!
Sorry...It was late last night when I posted my last message!
"Speak" soon,
Lee
|
Top
|
|
|
|
#79402 - 2003-01-09 05:55 PM
Re: iif() stack overflow exception "problem"?
|
Anonymous
Anonymous
Unregistered
|
First of all, let me say that I was really excited to see the true community-power at work in this thread. The initial post was intriguing, and your combined responses have produced the exact cause and appropriate work arounds. Makes me feel proud to be part of this community!
And, as a result of your efforts, my response can be short: the phenomenon is indeed caused by the fact that all parameters of a function are always evaluated. Changing this behaviour would be non-trivial, and might break downward compatibility.
Basically, IIF() is just a bit of 'syntactical candy' which can make certain scripts shorter. If readability and performance are your main concern, good old IF is probably a better choice.
Thanks to all the participants, and keep scripting!
Ruud
|
Top
|
|
|
|
#79404 - 2003-01-10 10:16 AM
Re: iif() stack overflow exception "problem"?
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Agreed, the manual should explicitly state the situations in which IIF() should be used, and the pitfalls of having the expressions always evaluated.
It caught me out at first as coming from a mainly 'C' background I am used to the ternary "?:" operator which appears to work in a similar way. The form is: quote: (condition) ? (True-expression) : (False-expression);
The difference is that this is a language construct, and only the expression which corresponds to the result of the condition expression is evaluated.
The fact that IIF() is a function implies that the parameters must be evaluated first, but it will save some headaches if it is spelled out explicitly in the documentation.
|
Top
|
|
|
|
#79408 - 2003-01-10 04:40 PM
Re: iif() stack overflow exception "problem"?
|
Lee Wilmott
Starting to like KiXtart
Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
|
I totally agree with you shawn... quote: IIF's are ok as long as one fully understands what one is doing
Using iif() is fine...as long as you understand what it is doing and how it is doing it!
Lee
|
Top
|
|
|
|
Moderator: ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 920 anonymous users online.
|
|
|