Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
AND and OR evaluations in conditional statements
Message
 
 
À
13/04/1999 12:14:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00206066
Message ID:
00208057
Vues:
30
Jim,

>So WHY do you attribute this to "the optimizer", that is the question?

Because I know of no other thing to credit the optimization to. How else can you explain why l2() is never called in this code:

? l1() or l2()

function l1
? program()
return .t.

function l2
? program()
return .f.

>I also stated in my reply that we are told in virtually ALL programming languages to 'self-optimize' logical statements to avoid extra (and unnecessary) processing.

Yes, this is good common sense programming. It also helps even more if the compiler can also optimize the actual evaluation. FP2.x and VFP optimize logical expressions. Not every compiler does this optimization. I do not think (several year old memory here so it might be clouded by age *s*) dBASE IV did logical expression optimization.

>*IF* VFP indeed has an "optimizer" for logical statements, this would be the first that I have EVER heard of it! As you have done, some may speculate that that is the case.

Maybe you learned something new.

>There is absolute no way that your assertion that " This is a completely false statement " is borne out by your example as virtually every language would perform in the same way. Yes, some might do a complete syntactical check of a whole statement before executing it, and some may even perform complete operand type-compatibility checks before executing the statement. We know that FP/VFP *previously* did not check for these things because we could have a syntax error or even a type conflict which went undetected *UNTIL* a case arose where the (further along) part of the statement actually got interpreted/executed. This has been reported as fixed for some time now, so if anything VFP is now less 'optimized' than it used to be.

Yes, the VFP compiler is more strict than earlier versions. It finds code errors like extra right parens that earlier compilers did not catch. The compiler does indeed syntactically evaluate the whole expression to put it into a binary tree for runtime evaluation, at least this is the way most compilers work. You can refer to any book on Compiler Design for more information on the subject. We can also tell that operands aren't evaluated unnecessarily in the case that you put a code runtime error in t2() above, something like x = 1 + 'a' this passes the syntax check but fails at runtime. I think you are slightly confusing the roles of the compiler/parser and the runtime evaluation of the "object" code. VFP is no less optimized than FP2.x used to be.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform