Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why define constants
Message
From
24/10/2006 20:08:22
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
24/10/2006 20:05:11
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01164235
Message ID:
01164236
Views:
16
One important advantage is when it is used in several places.

Another reason to define constants is that it may make code easier to read.

For instance, you might use the defined constants for the MessageBox() function; using something like MB_YES instead of the numerical constant makes the function call easier to read.

In this case, it is not likely the constants will change in the future - it is just for readability.

>Could someone educate me as to why it is standard practice to define constants with a variable name rather than to just use the constant in the code?
>
>IE, why is:
>
>#define MY_CONSTANT "My constant"
>? MY_CONSTANT
>
>better than
>
>? "My constant"
>
>
>I understand that it may make it easier to change the value of the constant if the need arises during design, but if the constant is only used in one place in the application is there still an advantage?
>
>Thanks for any enlightenment.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform