溪边树

象一棵树,栽在溪水旁。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Good Programming Practice -- Chapter 4

Posted on 2010-01-21 15:47  溪边树  阅读(179)  评论(0编辑  收藏  举报

All the following words are from the book "C++ How to Program, Fifth Edition", H.M. Deitel. Any commercial using is firmly denied.

Good Programming Practice 4.1

Consistently applying reasonable indentation convertions throughout your programs greatly improves progam readability. We suggest three blanks per indent. Some people prefer using tabs but these can vary across editors, causing a program written on one editor to aligh differently when used with another.

Good Programming Practice 4.2

Always putting the braces in an if ... else statement (or any control statement) helps prevent their accidental omission, especially when adding statements to an if or else clause at a later time. To avoid omitting one or both of the braces, some programmers prefer to type the beginning and ending braces of blocks even before typing the individual statements within the braces. 

Good Programming Practice 4.3

Separate declarations from other statements in functions with a blank line for readability. Declare each variable on a separate line with its own comment to make your programs more readable.

Good Programming Practice 4.4

Prompt the user for each keyboard input. The prompt should indicate the form of the input and any special input values. For example, in a sentinel-controlled loop, the prompts requesting data entry should explictly remind the user what the sentinel value is.

Good Programming Practice 4.5

Unlike binary operators, the unary increment and decrement operators should be placed next to their operands, with no intervening spaces.