Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why define constants
Message
From
27/10/2006 10:04:27
 
 
To
24/10/2006 20:05:11
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01164235
Message ID:
01165004
Views:
12
Not having read all of this lengthy conversation, but in general not having seen more cons than pros, here are some useful cases for defines in my opinion:

1. Self defined error constants:
#define errInvalidPcount -1
#define errInvalidParameterType -2
...
Used throughout many, many procedures/functions/methods in parameter check portions of code. You may centralize parameter checks in some way, but at what cost? a central parameter check routine whould need to know the rules it must apply to the parameters it got. You may come up with something data driven. I think I stay with local parameter checks, reusing the same error numbers all over the place, but as easier to remember constant names.

2. intellisense supporting constants
#define coSomething This.oSomething
#if .f.
   local coSomething as myClass of ...\myclasses.prg
#endif
coSomething. && intellisense jumps in
Especially if oSomething is added at runtime only.

3. downward compatibilty constants
#if Version(4) < "09.00"
    #define SomeNewFunction mySomenewfunction
#endif
With this or some modification I can use new functions/parameters and still have the code downward compatible for older vfp versions, if I can write a function mySomenewfunction() that can replace the new one by just using available old functions/commands. I then don't need to avoid the new function to be downward compatible.

There are some more cases. One is having the opportunity to group constants and #include whatever is needed at a certain level. Eg begin with some general.h file and include that anywhere via a local.h with an #include general.h inside makes it possible to use some constants like CRLF throughout all code, although you can only define a single include file for a class of a classlib through menu->class->include file.

Bye, Olaf.
Previous
Reply
Map
View

Click here to load this message in the networking platform