




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Best practices for using variables effectively in programming, including the importance of using clear and descriptive names, initializing variables properly, and limiting the scope and persistence of variables. It covers topics such as naming conventions, variable names, enum names, and variable initialization and use.
Typology: Slides
1 / 8
This page cannot be seen from the preview
Don't miss anything!





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
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
Use opposites precisely Avoid the use of the word flag Use boolean names done / error / found / success The name should imply true or false
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
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