名字和标识
44 Names should be common English words, descriptive of what the function, argument, or
variable does
44 名字应该是普通英文单词,用来描述这个函数、参数或者变量的作用
44.1.Do not clutter names with gibberish
44.1 不要乱起名字(无意义的,深奥的,不贴切的)
45 Macro names should be ENTIRELY_CAPITALIZED
45 宏名字应该形如:ENTIRELY_CAPITALIZED
45.1 Do not capitalize members of an enum
45.1 不要将枚举类型成员大写
45.2 Do not capitalize type names created with a typedef
45.2 不要将用typedef定义的类型大写
46 Avoid the ANSI C name space
46 避免ANSI C名字空间
47 Avoid the Microsoft name space
47 避免微软名字空间
48 Avoid unnecessary symbols
48避免不必要的符号
49 Symbolic constants for Boolean values are rarely necessary
49 布尔型符号常量基本上没有用
一般编程原则
50 Don't confuse familiarity with readability
50 熟悉代码与代码的可读性好是两回事
51 A function should do only one thing
51 一个函数只应该完成一件事
52 Too many levels of abstraction or encapsulation are as bad as too few
52 过多或者过少的抽象或者封装层次都不好
53 A function should be called more than once, but?br>
53 一个函数应该被多处调用
53.1 Code used more than once should be put into a function
53.1 在多于一处使用的代码应该变成一个函数
54 A function should have only one exit point
54 一个函数应该只有一个退出点
54.1 Always put a return at the outer level
54.1 总是在外层放一个return
55 Avoid duplication of effort
55 避免费两遍事的事情
56 Don't corrupt the global name space
56 不要污染全局名字空间
56.1 Avoid global symbols
56.1 避免全局符号
56.2 Never require initialization of a global variable to call a function
56.2 对函数的调用不应该依赖全局变量是否被初始化
56.2.1 Make locals static in recursive functions if the value doesn't span a recursive call
56.2.1 在第归函数中,如果一个变量与第归调用无关,则其应该是局部静态变量
56.3 Use instance counts in place of initialization functions
56.3 在初始化函数中使用实例计数
56.4 If an if ends in return, don't use else
56.4 如果if语句中有return,则不要再写else
57 Put the shortest clause of an if/else on top
57 最短的if/else子句在最上面
58 Try to move errors from run time to compile time
58 尽量将运行时刻的错误提前到编译时刻
59 Use C function pointers as selectors
59 使用C 函数指针作为选择器
60 Avoid do/while loops
60 避免do/while循环
60.1 Never use a do/while for a forever loop
60.1 不要用do/while实现无限循环
61 Counting loops should count down if possible
61 循环计数应该从大到小
62 Don't do the same thing in two ways at the same time
62 在同一时间不要用不同的方法完成同一件事
63 Use for if any two of an initialization, test, or increment are present
63 如果初始化、测试、增量三者有两个,就应该用for语句
64 If it doesn't appear in the test, it shouldn't appear in the other parts of for statement
64 没有在for语句的测试部分出现的变量,也不应该出现在其他两个部分
65 Assume that things will go wrong
65 总是假定事情要出错
66 Computers do not know mathematics
66 计算机不懂得数学
66.1 Expect the impossible
66.1 总是会出现不可能的事情
66.2 Always check error-return codes
66.2 检查错误返回代码
67 Avoid explicit temporary variables
67 避免显式临时变量
68 No magic numbers
68 不要出现纯数字
69 Make no assumptions about sizes
69 不要对size做假定
70 Beware of casts (C issues)
70 对类型转换要小心(C语言问题)
71 Handle special cases directly
71 立即处理特殊情况
72 Don't try to make lint happy
72 用不着试图让lint不报告问题
73 Put memory allocation and deallocation code in the same place
73 分配内存和释放内存应该在一起
74 Heap memory is expensive
74 堆内存是昂贵的
75 Test routines should not be interactive
75 测试过程不应该是交互的
76 An error message should tell the user what's right
76 错误信息应该告诉用户什么是正确的
77 Don't print error messages if an error is recoverable
77 如果一个错误是可恢复的,就不要打印错误信息
78 Don't use system-dependent functions for error messages
78 不要在错误信息中使用系统相关的函数