Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why define constants
Message
From
25/10/2006 11:25:26
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01164235
Message ID:
01164416
Views:
7
>>>>>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.
>>>
>>>In which case you have to look up in the header file what the text actually is. E.g. to check whether MESS stands for message or for 'what a mess'. <g>
>>
>>Only if you happen to be displaying the wrong message, otherwise it don't cares to the programmer.
>
>Or if your successor tries to understand the logic of the code.

Again, my successor is a programmer too and he don't cares either. However, it won't kill him to have the define text file open as a reference window. On that point, myself I have it open sometimes for the MESSAGEBOX() components. Oooh, such a pain!
- Whoever said that women are the weaker sex never tried to wrest the bedclothes off one in the middle of the night
- Worry is the interest you pay, in advance, for a loan that you may never need to take out.
Previous
Reply
Map
View

Click here to load this message in the networking platform