Variable Naming Convention Best Practice

  1. Make your variable names long and descriptive.
    • Using long names prevents the ambiguity of short or cryptic names.
  2. Put units in your variable names
    • If you are writing an engineering application you are going to be using variables with units. Embed the unit name in the variable, for example, distanceInMM.
  3. If you are using Camel Case, don't capitalise commonly hyphened, or combined words.
    • Callback is normally spelled as one word. So don't call your variable callBack.
  4. Never, ever use the variable name temp.
    • The only perfectly valid exception to this rule, is when you're writing a swap function.
  5. int i is perfectly valid in a small loop.
    • When your loop is half a dozen lines of code long or less, int i is perfectly valid as a loop counter.

Source and Other References

 
variable_names.txt · Last modified: 2009/03/18 19:24 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki