暑假读书笔记2-《代码大全》

今天把变量名部分看完了,变量命名,以后要按一定规则了,虽然麻烦一点,但是以后会方便很多。

顺便贴一下书中总结的要点:(书是中文的,不过电子版我只找到英文的,就贴英文的好了)

Checklist: Naming Variables

General Naming Considerations

  • Does the name fully and accurately describe what the variable represents?

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

  • Is the name long enough that you don’t have to puzzle it out?

  • Are computed-value qualifiers, if any, at the end of the name?

  • Does the name use Count or Index instead of Num?

Naming Specific Kinds of Data

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

  • Have all "temporary" variables been renamed to something more meaningful?

  • Are boolean variables named so that their meanings when they’re true are clear?

  • Do enumerated-type names include a prefix or suffix that indicates the category—for example, Color_ for Color_Red, Color_Green, Color_Blue, and so on?

  • Are named constants named for the abstract entities they represent rather than the numbers they refer to?

Naming Conventions

  • Does the convention distinguish among local, class, and global data?

  • Does the convention distinguish among type names, named constants, enumerated types, and variables?

  • Does the convention identify input-only parameters to routines in languages that don’t enforce them?

  • Is the convention as compatible as possible with standard conventions for the language?

  • Are names formatted for readability?

Short Names

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

  • Does the code avoid abbreviations that save only one character?

  • Are all words abbreviated consistently?

  • Are the names pronounceable?

  • Are names that could be misread or mispronounced avoided?

  • Are short names documented in translation tables?

Common Naming Problems: Have You Avoided…

  • …names that are misleading?

  • …names with similar meanings?

  • …names that are different by only one or two characters?

  • …names that sound similar?

  • …names that use numerals?

  • …names intentionally misspelled to make them shorter?

  • …names that are commonly misspelled in English?

  • …names that conflict with standard library routine names or with predefined variable names?

  • …totally arbitrary names?

  • …hard-to-read characters?

© 2007, QP. 版权所有.

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇