Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
#DEFINE - Why?
Message
From
31/03/2008 17:35:10
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01306848
Message ID:
01307166
Views:
11
I wonder how much memory we are talking about though? 100k? We are only talking about values like "LOOK_AT_THIS_COOL_DEFINE" and stuff like that. Maybe it comes down to how memory is assigned and it does save a bunch, but I'm thinking it's not really that much.


>If you have many constants, then defines will save memory.
>
>>That seems to be the biggest difference. Readability. Of course the choice is mine, I'm just not seeing the big advantage. It's just another way to do something, which is one of the things Foxpro does very well. Gives you choices.
>>
>>>I work on many different applications. I have a standard .H file where several of these reused constants are defined. As with the FoxPro.H file, I include the standard in the application once. Not only does it contains character to Constant definition, but also our company info, a few other constants that are used everywhere.
>>>
>>>I uses constants to ease the readability and lessen the time to type the code. But the chose its yours.
>>>
>>>>Um...
>>>>
>>>>m.Constant_CRLF = CHR(13)+CHR(10)
>>>>
>>>>or
>>>>
>>>>oProject.Constants.Constant_CRLF = CHR(13)+CHR(10)
>>>>
>>>>I think that works too.
>>>>
>>>>>>Isn't that more of an issue of coding practices rather than using a variable vs defines? I can do the same thing you just said with variables.
>>>>>
>>>>>Besides, do like type CHR(13)+CHR(10) all over the place, or would it be easier to type CRLF.
>>>>>
>>>>>#DEFINE CRLF CHR(13)+CHR(10)
>>>>>
>>>>>>
>>>>>>>Then look at this from a maintenance viewpoint. Values that appear in code are called, "magic numbers". They do something, but you don't necessarily know what they mean. It's just a number. And, it may appear in several places, which means if the value changes at some point, you have to hunt them all down. If you use a #DEFINE, you can give the number some meaningful name. And, if all the #DEFINEs are in a single file, you only have to go one place to change them.
>>>>>>>
>>>>>>>Run down to your local Borders bookstore and find the book "Code Complete" by Steve McConnell and read about magic numbers.
>>>>>>>
>>>>>>>
>>>>>>>>Is this an issue really?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform