General ISSUES in Using Variables

xiaoxiao2021-03-06  60

.

Initializing VariablesImproper data initialization is one of the most fertile sources of error in computer programming.1. Initialize each variable as it's declared.2. Initialize each variable close to where it's first used.If the language does not support initializing variables as they ' are declared, then use the 2.3. Ideally, declare and define each variable close to where it's used.4. Pay special attention to counters and accumulators.A common error is forgetting to reset a counter or an accumulator before the next time it's used. 5. Initialize a class's memeber data in its constructor.6 check the need for reinitialization.7 Inititalize named constants once;.. initialize variables with executable code.8 Use the compiler setting that automatically initializes all variables.9 Check input parameters for.. Validity.before you assign Input Values ​​To Anything, Make Sure The VALUES..

Scope of variableKeep variables live for as short a time as possible.1. Initialize variables used in a loop immediately before the loop rather than back at the beginning of the routine containing the loop.2. Do not assign a value to a variable until Just Before The Value IS Used.3. Group Related Statements.example In P144. Begin With Most Restricated Visibility, and Expand The Variable's Scope Only if Necessary.

.

转载请注明原文地址:https://www.9cbs.com/read-111650.html

New Post(0)