Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variables - Private vs. Local
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00882138
Message ID:
00884099
Views:
11
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
Previous
Reply
Map
View

Click here to load this message in the networking platform