Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why define constants
Message
From
26/10/2006 06:36:32
 
 
To
25/10/2006 13:37:47
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01164235
Message ID:
01164654
Views:
12
Hi Walter

To be honest, I've rarely found the need for them, except in, say, the MessageBox() example, and THAT dates back to pre-VFP7 when there wasn't "mother's little helper" popping up all over the place. I generally had to look up the codes in Help. I still opine though that a meaningful constant name beats a number for readability.

As for funcs, yes, then defines may well obfuscate the code; the few examples I did were just for fun and I couldn't be arsed preparing defines like that (and to what goal?).

Back in my earlier s/w engineering days, when we used PLM86, we'd use little ruses like:

Do Forever

(where "forever" was defined as "while TRUE" or "while 0" - can't quite remember)

instead of:

Do while TRUE (which doesn't make much linguistic sense)

and a few similar wee novelties, but not to a large extent.

Now, almost exclusively in my career I've developed VFP apps totally on my own, so I know what I'm talking about in my code. BUT, if I were in a largish dev team then I can see the merit of having a #define lib somewhere, esp. for, say error messages. Thus a member could check if an approp. message has already been defined by another member, promoting consistancy in the message (and, indeed, a subject close to my heart, in its grammar, semantics, syntax and spelling). Maybe there could be a "message tsar" who defines the wording to all, for example.

Terry

PS your 2 cents' worth is worth only c. .67 of my two penn'orth :-)


>Hi terry,
>
>Just to throw in my 2 cents,
>
>In general I find using .h files and #DEFINES a pain in the but. You'll not find them a lot, even in a major application I'm working on know.
>
>The cases where I use them is where a numbers are used to identify certain cases. E.g.
>
>
Action:
>1 - Move
>2 - Discard
>3 - Ship
>4 - Extent consent
>5 - Thaw
>
>btw, this is from a cryopreservation module in an application i'm working on. The audit trial records what happened with frozen specimen, through fixed codes. In those cases I can see a #DEFINE making sense.
>
>There are a few limited number of other places where I (might) use them, but for simple Messagebox functionality I'd rather use intellisense and or a comment.
>
>In general I hate to see them in my code, they tend to obscure my code. I simply hate those cases where the #DEFINE is more than just a constant value, but rather a function or so. It simply makes things more complicated and by the time you want to use such method, it may be time to rethink your coding strategy.
>
>Walter,
>
...
- 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