Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which Should I Use IF/ENDIF or IIF
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00668532
Message ID:
00670303
Views:
40
I typically reference memvars with m. to avoid any possible confusion with fields of the same name as well as, IMO, it makes the code more readable. In the thread several weeks ago there were some almost heated disagreements for one way or the other. I ran some tests using both and found that the results were not that significantly different in over a million iterations with either. On some tests using m. was faster, in others not using m. was a little faster. My point is that if you are careful with proper declaration of variables as to scope (local or private or even public) it really doesn't seem to make that much of a performance hit either way.

As for using if.. else..endif or iif(), I use both. If.. Else.. endif is a little more readable in code when the condition is somewhat complex or if there are nested if's. Iif() if very handy for setting a conditional value to a variable for simple conditions and for use in report expressions, and it is just as readable when conditons are not complex or nested. In testing, the results vary as to which is faster depending on any number of factors, but the speed difference is in most cases so slight that it doesn't present a compelling reason to abandon one for the other.

My goal is to design the logic to be as efficient and bug free as possible and effectively use the tools that are available to me to get the job done. I am always looking into better ways to do things but the debate on m. or not to m. for variables and if/endif or iif() has not proven either to be consistently better than the other in testing and IMHO, your choice on each can be considered a matter of personal preference and programming style.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform