Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Constants vs Locals
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00269906
Message ID:
00270013
Views:
29
>>Defined constants are like anything else in programming. Used correctly they can be extremely important in the areas of readability, reduction of overall application size, and performance. Used incorrectly (abused, if you ask me), they can make maintenance a nightmare.
>>
>>As far as I'm concerned, in most cases, if you're worrying about the underlying value of the constant or need to know it, it's a strong hint that it's being mis-used. So my rule of thumb in this regard is to use it in those cases where you really don't care as much about the meaning as you do what it represents. Take the MESSAGEBOX() constants, I don't particularly care about what the underlying values are, but I do care about their meaning. Simple illustration would be seeing a return shown as MB_IDYES or 6 (and I had to look it up)?:-)
>
>Hi George - Let me use Jim's PI example...does it really matter whether you use a local or a #define for the PI value? I've always used locals or properties for such things, but am wondering if it's worth moving to constants.

Hi Bruce,

With all due respect to JimB, I don't think that the PI example is a very good since we've got the value as a function. It does, however, point at the root of the problem. Ignoring the function, using such a value could lead to problems and questions (accurate to how many decimal places? , where is that defined?).

So let me answer in this way. Constants used this way are sometimes referred to as "Symbolic Constants". That provides a significant information about how to use them and perhaps demonstrates what I was getting at. Used in this way, we don't care about the underlying value. It's simply a value being used to represent something else in a more readable and maintainable fashion.

If a gain in performance can be realized by using something like the PI example (and I know that this is sometimes an issue with you), then have to weigh the gains against the potential problems that might be caused. This is one of the more difficult decisions we have to make in system design and implementation, since we're called on to be something more akin to a seer or fortune teller. However, it's part of the job, so waddya gonna do?< g >
George

Ubi caritas et amor, deus ibi est
Previous
Reply
Map
View

Click here to load this message in the networking platform