Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Always stops evaluating if..?
Message
De
17/08/2005 03:57:50
 
 
À
15/08/2005 19:56:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
Divers
Thread ID:
01041159
Message ID:
01041556
Vues:
19
>>>As far as I know, vfp always stops evaluating the right remainder of a logical expression if the left part evaluates to an logical value that cannot be changed anymore by the right remainder. For example, in the case of IF A OR B, the B is no longer evaluated if A evaluates to True. In a same vein, in the case of IF A=0 or BB(), the function BB is not visited if A=0.
>>>
>>>But now I am confronted with a case in a select-sql WHERE expression, where the part to the right of the OR is visited anyhow, notwithstanding the result of the left expression.
WHERE ( MOD(A,1000)#0 OR THERMO(A) )
>>>
>>>Does this sound familiar to anyone here?
>>
>>I suppose that within a SQL command different rules apply, what with Rushmore Optimization. For example, in one particular case Visual FoxPro might decide that it is more efficient to evaluate the right-hand member first, because it is Rushmore-Optimizable. In any case, I wouldn't count on the right-hand expression not being evaluated within a SQL command (on the other hand, I would trust VFP to do shortcut boolean evaluation in most other cases).
>>
>>If shortcut boolean evaluation is important in this case, you might move the entire combined expression to a UDF, or change it to an IIF().
>
>Great, your tip to use IIF did help!
WHERE IIF(MOD(A,1000)=0,THERMO(A),.T.)
And that's the most important thing for me now. Remains the quest whether the rule is not valid inside a SQL command. If that is indeed the case, then it should be documented, at the least.

Some languages are guaranteed to support left-to-right conditional execution as you outlined in your original message. AFAIK xBASE/VFP is NOT one of them - I don't recall ever seeing any official confirmation of this, either in documentation or by Microsoft. If that's the case there's no need to document this behaviour because you shouldn't be relying on it in the first place.

Personally I never use left-to-right conditional execution even in languages that explicitly support it. IMO it makes code hard to understand and is a significant source of nasty bugs. Not to mention that these days, vendors are working hard on optimizing compilers which, if they're at all buggy, will likely have effects like you've seen here. Just say no ;)
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform