Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable Naming
Message
De
08/01/2000 20:20:37
 
 
À
08/01/2000 18:21:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00315006
Message ID:
00315044
Vues:
32
>lcname is a local character
>pcname will never exist in my program, but it would be a public character
>
>Why should I bother?
>

To some extent, the scopimng prefix in the commonly used Hungarian notation variant that everybody uses is a consession to "the bad old day" before we had real local vcariables; by having all "local" things start with a common character, we could take advantage of the masking cpability of the PRIVATE statement; IOW, by making certain that all locals started with the letter 'j' (junk), we could emulate the behavior of locals by adding the statement:

PRIVATE ALL LIKE j*

to each procedure or function, thereby hiding any variable declared at a higher level that started with a j; the advent of the LOCAL statement made this less of a necessity, but for many programmers, it was a standard, and adherence to a standard, even if unnecessary, still makes understanding what the intended scope of a variable would be clearer.

I feel that the second character, which specifies the intended datatype of the variable, a far more useful piece of information when debugging; it helps me spot inconsistent treatment of variables when trying to figure out "why didit dew that?" Since I find it helpful, I use the notation consistently, because ti helps me understand where I screwed up or misunderstood what was really happening.

I tend to prefix parameters with 't' when I expect a pass by value, or s for pass by reference, where I use the parameter to pass something back. Arrays get an 'a' designation to help me spot such disasterous behavior as assigning a value to an array unintentioanlly, thereby resetting all the values.

IOW, the importance of these standards is as an aid to the developer, much as consistent indentation and standard comment blocks help by providing quick visual clues about expected system behavior and scoping.

>What is with prefixing variables with their types? It doesn't take me long to figure out (ie, no time) that if you are doing numeric manipulation to a variable, its a number!
>
>Wouldn't it be better to define prefixes for where I expect the variable to be used? That way, if I end up in a debugger somewhere, I can tell where the variables were first defined.
>

Well, with very few exceptions, names tend to be local, so I want variant scoping to stand out, and knowing the type of data I should expect to see provides a quick 'heads up' when tracking down data type mismatches and syntax errors. A variable with a type of 'U' is a warning to me when I use it in an expression...

>And, what if I am moving variables into fields and fields into variables... Its a lot more convienant to call the variable the same as the field.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform