Identifier Naming Practices
- Details
- Category: Programming
- Published on Friday, 14 October 2011 20:23
- Written by Kinda Strange
- Hits: 146
Identifier names should carry descriptions of the entities they represent rather than being based on personal preferences.
It’s helpful to use pronounceable names to make it easier to discuss programs with developers and other collaborators.
Ideally, the length of a variable should be between 10 and 16 characters, neither too long nor too short. Local variables should have shorter names than global variables.
Classes and objects should be named with nouns and/or noun phrases, such as ‘customer_Age’ or ‘phone_Number’. Functions should be named with verbs and/or verb phrases, such as ‘display_Time’ or ‘calculate_Pay’.
For loops, counter variables are usually i, j, or k.
Provide meaningful names for status variables to ensure code is comprehensible.
Names given to Boolean variables should suggest that the variable contains either a ‘True’ or a ‘False’.
Use names for constants that are descriptive of their meaning rather than the number they represent.
Use standard abbreviations when available. Abbreviations should use the first letter of each word, or the first few letters of each word. Use the same abbreviated name consistently.
Do not create variable names that are similar in pronunciation.
Avoid mixing numerals with letters.
Do not use programming language keywords as variable names
Avoid frequently misspelled words
Avoid having variable or function names that are too similar to each other.


