Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
#DEFINE - Why?
Message
De
01/04/2008 08:47:11
 
 
À
31/03/2008 16:58:30
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01306848
Message ID:
01307275
Vues:
9
One of the things I like about any xBase language is the fact that it is easy to read even without comments. I believe any language that requires comments to interrupt what it is suppose to do is in antiquate.

Currently, I am maintaining a LARGE application that was recovered using OutFox. No Comments. Even the code is not formatted properly. I probably fined myself spending a third of my time reformatting the original code to better understand it.

Yet...

Sometime, I discover a reoccurring value.

These, I will eventually place as constants so I have only one place that needs to be changed.

But, beware, things like tax rates should NEVER be hard coded (constants). Things like PI and other unmoving values can (CRLF).

DEFINE statements have great benefits, but use them sparingly. Look to the future and ask yourself "Will I need this later?"

>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 thnk 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?
Greg Reichert
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform