You are here

Good Programming Techniques

5 February, 2015 - 11:20
  • Meaningful
  • Be case consistent

Meaningful identifier names make your code easier for another to understand. After all what does "p" mean? Is it pi, price, pennies, etc. Thus do not use cryptic (look it up in the dictionary) identifier names.

Some programming languages treat upper and lower case letters used in identifier names as the same. Thus: pig and Pig are treated as the same identifier name. Unknown to you the programmer, the compiler usually forces all identifier names to upper case. Thus: pig and Pig both get changed to PIG. However not all programming languages act this way. Some will treat upper and lower case letters as being different things. Thus: pig and Pig are two different identifier names. If you declare it as pig and then reference it in your code later as Pig you get a compiler error. To avoid the problem altogether, we teach students to be case consistent. Use an identifier name only once and spell it (upper and lower case) the same way within your program.