Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why define constants
Message
From
25/10/2006 07:10:05
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01164235
Message ID:
01164302
Views:
10
>>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.
>
>Another example:
>
>You have a 3-line error message that you need to put in a call TO MESSAGEBOX(). Insted of writing a space-consuming, messy MESSAGEBOX message you could just include, say, ERR_MESS_NO_MEDIA. ERR_MESS_NEED_REBOOT, etc.

And in these days of 128 character variable names all that looks like extra work for very little gian (if any).
In general my view is that #DEFINEs are more trouble than they're worth.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform