Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
#DEFINE - Why?
Message
 
 
À
31/03/2008 06:57:46
James Beerbower
James Beerbower Enterprises
Hochheim Am Main, Allemagne
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:
01306902
Vues:
6
>>What is the simplest explanation as to why these are needed? Why not just set regular variable values? So what if they are constant and don't change?
>
>A lot of people have given reasons for using #DEFINES. I don't like them much and the main reason is that like all other indirection it makes other peoples code harder to work with. At the start of the program there is an #include but where is this file that will be included? I have to track it down. It's based on PATH. God forfend they were smart and use a different define based on different paths. In this regard it is similar to problems working with global variables.
>
>The code is more complex to steal or refactor. An example: if I want to crop part of a function from someone and use it in my program then I have to make sure that I get all the defines found and included. If they were variables they would have been defined in the function locally or passed as parameters.
>
>Another example 3.1427 * m.lnRadius is for me easier to read than MATH_GEOMETRTY_PI*m.lnRadius or something like that -- unless I invented the define name myself.
>
>Another disadvantage with DEFINES is that you can't change the values on the fly -- say to get around a runtime crash.
>
>Still I suppose there are good reasons for using defines if you have the sort of application where the performance advantage makes a difference.

That's a good point about having to find the #INCLUDE file, if that's where the DEFINEs reside.

Personally I wouldn't use, or not use, defined constants for performance reasons. It's hard to imagine the difference being worth worrying about.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform