Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MESSAGEBOX
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00365597
Message ID:
00366022
Vues:
13
>>Hey all.
>>
>>Maybe this is rhetorical.
>>
>>But why do almost all VFP code examples insist on using a #DEFINE variable for MESSAGEBOXs?
>
>I know and acknowledge all of the textbook reasons to use DEFINEs. Steve McConnel states that "magic numbers" are always a no-no. A magic number is any hardcoded numeric literal whose number is arbitrary. IOW, the only numbers you should have in your code are like 1 for a loop, or 2 for an array dimension. All others are bad. I agree.
>
>BUUUUUUUT. The practical issues involved with littering your code with constants make the practice unbearable, IMO. At least in VFP. VFP is extremely goofy with regard to the "scope" of an include file, and its behavior with constants in the debugger, and its sometimes mysterious tendency to forget where include files are. As a result of these PITAs, I almost never use defined constants.

Erik,

I'll agree about VFP and the scoping issues it has with include files in general. However, I'll disagree about the worthiness of the practice with both you and John.

First, I think it's human nature to think terms of ourselves first. Several years ago, I had an incident with a co-worker. I commented that the implementation of a certain practice would make her code more readable. Her response was, "I can read it fine". Mine was, "You may not always be the one having to read it." Sure enough, I ended up having to modify the code, and spent far too much time trying to figure it out. Ultimately, she did a disservice to the company by not following my suggestion. I believe the same applies here.

If you're 100% certain that you'll be the only one who ever has to work with the code, yeah, "Who cares?" However, and this particularly applies to me, if you're not, then you're doing a similar disservice to whomever has to deal with the code.

Sure, the current MessageBox() flag values are fairly easy to remember. What if, however, the in next version of VFP the function maps to MessageBoxEx(). Whoops, there's a whole new bunch of values to remember. Does anyone, off the top of their head know, for example (and no cheating), what the value is for MB_HELP? I don't, and further, I don't want to have to spend the time either memorizing it, or creating a chart to help me remember.

Getting away from the MessageBox() in particular. How about these four for accessing the registry: HKEY_CLASSES_ROOT, HKEY_LOCAL_MACHINE, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER? Again, without looking them up, what are those values? I was able to sit here and type these out without looking to see what they the key names were. The values? I don't have a clue.

I liken the constants to the mnemonics used in assembly language. I couldn't tell you what the particular values were for Return from Subroutine, Branch Not Equal, Increment the X register, or Pull the Accumulator from the stack were in 6502, but I can still tell you the mnemonic for each (RTS, BNE, INX, and PLA).

Just my take, however.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform