溪边树

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

Good Programming Practices -- Chapter 6

Posted on 2010-04-06 17:54  溪边树  阅读(259)  评论(1编辑  收藏  举报

Error-Prevention Tip 6.1: A small function that performs one task is easier to test and debug than a larger function that performs many tasks.

Error-Prevention Tip 6.2:If you have doubts about the order of evaluation of a function's arguments and whether the order would affect the values passed to the function, evaluate the arguments in separate assignment statements before the function call, assign the result of each expression to a local variable, then pass those variables as arguments to the function.

Error-Prevention Tip 6.3:Provide a default case in a switch to catch errors even if you are absolutely, positively certain that you have no bugs!

 

Good Programming Practice 6.1: Capitalize the first letter of an identifier used as a user-defined type name.

Good Programming Practice 6.2: Avoid variable names that hide names in outer scopes. This can be accomplished by avoiding the use of duplicate identifiers in a program.

Good Programming Practice 6.3:  Using default arguments can simplify writing function calls. However, some programmers feel that explicitly specifying all arguments is clear.

Good Programming Practice 6.4:  Always using the unary scope resolution operator (::) to refer to global variables makes programs easier to read and understand, because it makes it clear that your are intending to access a global variable rather than a nonglobal variable.

Good Programming Practice 6.5: Overlaoding functions that perform closely related tasks can make programs more readable and understandable.