CSDN博客

img wangjiong

Data Names

发表于2004/9/30 22:26:00  604人阅读

分类: Excerpt of CC2

1. Express exact meaning.
2. As short as possible.

Naming Loop Indexes
In common, we can use the names such as i,j and k; but when loop is long and complex, we should use a meaningful name like recordCount.

Naming Status Variables
Think of a better name than flag for status variables.

Naming Temporary Vriables
In one way or another, most of the variables in your program are temporary.  Calling a few of them temporary may indicate that you aren't sure of their real purpose. So also give it a meaningful name.

Naming Boolean Variable
Give boolean variables names that imply True of False, such as Is....
Use positive boolean variable names.

Naming Enumerated Types
Give a group prefix to these variables.

Conventions for names
1. Differentiate between variable and routine name.
variable name is begin with lower case and routine name with upper case.
2. Differentiate bwtween clases and objects
Differentiating them via initial Capitalization.
3. Identify global variables
use g_ prefix.
4. Identify member variables.
use m_ prefix.
5. Identify type definitions
prefix the type names before the variable.
6. Format names to enhance readability.
Two common techiniques for increasing readability are using capitalization and spacing characters to separate words.

Comments on Abbreviations
1. Don't abbreviate by removing one characters from a word.
2. Abbreviate consistenly.
3. Create names that you can pronounce.
4. Avoid combinations that result in mispronunciation.
5. Use a thesaurus to resolve naming collisions.
6. Document extremely short names with translation tables in the code.
7. Document all abbreviations in a project-level "Standard Abbreviations" document.

Kinds of Names to Avoid
1. Avoid misleading names or abbreviations.
2. Avoid names with similar meanings.
3. Avoid variables with different meanings but similar names.
4. Avoid names that sound similar.
5. Avoid numberals in names.
6. Avoid misspelled words in names.
7. Avoid words that are commonly misspelled in English.
8. Avoid names containing hard-to-read characters.

阅读全文
0 0

相关文章推荐

img
取 消
img