溪边树

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

Good Programming Practices -- chapter5

Posted on 2010-03-08 11:38  溪边树  阅读(146)  评论(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 5.1

Put a blank line before and after each control statement to make it stand out in the program.

Too many levels of nesting can make a program difficult to understand. As a rule, try to avoid using more than three levels of indentation.

Good Programming Practice 5.2

Vertical spacing above and below control statements and indentation of the bodies of control statements within the control statement headers give programs a two-dimentional appearance that greatly improves readability.

Good Programming Practice 5.3

Always including braces in a do...while statement helps eliminate ambiguity between the while statement and the do...while statement containing one statement.

do

  statement

while ( condition );

The last line --while (condition);-- might be  misinterpreted by the reader as a while statement containing as its body an empty statement.

 

Thus, use the following.

do

{

  statement

}while ( condition );