Presentation is loading. Please wait.

Presentation is loading. Please wait.

Best Practices for Variables

Similar presentations


Presentation on theme: "Best Practices for Variables"— Presentation transcript:

1 Best Practices for Variables

2 Introduction Don’t use implicitly declared variables (VB allows this – C# does not) Do use naming conventions Remove unused variables Use all variables that you declare

3 Naming Conventions Pascal case Camel case Hungarian

4 Variable Names (1) Variables should “accurately” and “fully” describe the entity Don’t use obscure abbreviations 1 character variable names are OK for scratch values i,j,k are common Put modifier at the end of names (not the beginning) Total, Sub, Average, Max

5 Variable Names (2) Use opposites precisely Use boolean names
Avoid the use of the word flag Use boolean names done / error / found / success The name should imply true or false

6 Enum Names Use a prefix that is the same as the enum name
I violate this rule

7 Variable Initialization
Declare and initialize variables together A variable’s declaration and first use should be together (or close) Use constants where possible Don’t use literal values

8 Variable Use Use variables for a single purpose
Don’t reuse counters and accumulators If you do, tell the reader Minimize scope visibility Use local variables over global variables where possible Minimize persistence Avoid names with hidden meanings


Download ppt "Best Practices for Variables"

Similar presentations


Ads by Google