Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variables - Private vs. Local
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00882138
Message ID:
00884099
Vues:
12
Dean,

>Do most developers define all the variables at the beginning of a routine, or declare them local as they are defined?

I (this topic is mostly an issue of personal preference) declare memvars at their particular scope. Probably 99% of the time it is LOCAL, the 0.999% that are PRIVATE come with a specific comment as to why it is being declared private instead of local. PUBLIC is rarely ever used and again get specifically commented.

Routine-wide memvars get declared at the top of the routine, localized scopes at point of use:
function XYZ( pcArg )

* make any early out, parameter validation tests

if ( isnull( pcArg ) )
   return ""
endif

local lcStr ...

... more code

local i && a more localized scope for i
i = at( ' ', lcStr )
if ( i > 0 )
   local j && j is only needed in this small chunk of conditional code
   ...
endif
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform