Naming Variables-From "Code Complete"

来源:互联网 发布:怎么找回淘宝店铺 编辑:程序博客网 时间:2024/06/06 08:41

Naming Variables Checklist:

1. General Naming Considerations:

1) Does the name fully and accurately describe what the variable represents?

2) Does the name refer to the real-world problem rather than to the programming -language solution ?

3) is the name long enough that you don't have to puzzle it out 

4) are computed-value qualifiers,if any, at the end of the name?


2. Naming Specific Kinds of Data

1) Are loop index names meaningful (something other than i,j,k if the loop is more than one or two lines long or is nested?)

2) have all 'temporary 'variables been renamed to something more meaningful ?

3) are Boolean variables named so that their meanings when they're TRUE are clear?

4) do enumerated-type names include a prefix or suffix that indicates the category -for example , Color_for Color_Red,Color_Green and so on ?

5) are named constants named for the abstract entities they represent rather than the numbers they refer to ?


3. Naming Conventions 

1) Does the convention distinguish among local,class ,global data ?

2) does the convention distinguish among type names, named constants ,enumerated types and variables ?

3) is the conversion as compatible as possible with standard convention for the language ?

4) are names formatted for readability?


4. Short Names:

1) Does the code use long names (unless it's necessary  to use short ones)?

2) does the code avoid abbreviations that save ONLY one character ?

3) are all Words abbreviated consistently ?

4) are the name pronounceable?

5) are namespace that could be mispronounced avoided?

6) are short names documented in translation table?


5. Common Naming Problems : Have you avoided

1) names that are misleading 

2) names with similar meanings

3) names that are different by ONLY one or two characters

4) names that are use numerals?

5) names intentionally misspelled to make them shorter 

6) names that are commonly misspelled in English 

7) names that conflict with standard library-routine names or with predefined  variable names?

8) totally arbitrary names?

9) hard to read characters?


0 0
原创粉丝点击