Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Always stops evaluating if..?
Message
From
21/08/2005 11:55:34
 
 
To
21/08/2005 10:02:36
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
Miscellaneous
Thread ID:
01041159
Message ID:
01042565
Views:
28
>>You seem not to understand why LTR was invented in the first place. It was designed as a speed optimization in the days when computers were slow and expensive. To this day, that's its reason to exist. If you want to continue to use a side-effect of that optimization for flow control in your programs, do so at your own risk.
>
>LTR is not only for speed optimization. It can also help you avoid errors, while making code shorter.
>
>Here is a typical VFP construct:
>
>
>if type("SomeVariable") = "L" and SomeVariable
>  ...
>endif
>
>
>The possible error in this case is: SomeVariable doesn't exist, or has the wrong type. (If you think this is unlikely in your code, replace with some other condition that would cause an error.)
>
>Note that since VFP evaluates from LTR, the part after the AND will not be evaluated if the variable doesn't exist.
>
>Of course, this is completely equivalent to:
>
>
>if type("SomeVariable") = "L"
>  if SomeVariable
>    ...
>  endif
>endif
>
>
>but I personally like the shorter version, and I think LTR can be trusted in this case.

But there are advantages to the alternative you've shown above...
1) It is crystal clear what is being done, even for those who don't know about the LTR feature;
2) Coding that way works for sure in every language.

Sure, it takes a few lines. But minimum lines # clarity.

cheers
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform