1. 你应经常运行lint,并研习其教诲,因为它的直觉和判断通常比你强得多。
Thou shalt run lint frequently and study its pronouncements with care, for verily its perception and judgement oft exceed thine.
2. 你不应访问NULL指针,因为这样只会导致混乱和疯狂。
Thou shalt not follow the NULL
pointer, for chaos and madness await thee at its end.
3. 你不应将所有函数参数都强制转换为期待的类型,即使你认为无需如此固执,才能避免迟早会到来的报应。
Thou shalt cast all function arguments to the expected type if they are not of that type already, even when thou art convinced that this is unnecessary, lest they take cruel vengeance upon thee when thou least expect it.
4. 如果头文件没有给库函数定义返回类型,你应该谨慎地自行定义,以避免对程序造成伤害。
If thy header files fail to declare the return types of thy library functions, thou shalt declare them thyself with the most meticulous care, lest grievous harm befall thy program.
5. 你应当检查所有字符串(以及所有数组)的数组边界,因为肯定有人会在该输入 foo 的地方输入 supercalifragilisticexpialidocious。
Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
6. 如果一个函数声称在遇到问题时会返回错误码,那么你应当检查错误码,即使这样做会让代码量变成三倍。如果你认为“不会发生在我头上”,那么神一定会惩罚你的傲慢。
If a function be advertised to return an error code in the event of difficulties, thou shalt check for that code, yea, even though the checks triple the size of thy code and produce aches in thy typing fingers, for if thou thinkest ``it cannot happen to me'', the gods shall surely punish thee for thy arrogance.
7. 你应当学习库,尽量不要重新发明,因为库的代码更短、更易懂,能让你更快乐、更有效率。
Thou shalt study thy libraries and strive not to reinvent them without cause, that thy code may be short and readable and thy days pleasant and productive.
8. 不管你喜不喜欢,你应当使用1TBR风格,让程序的目的和结构能被同事理解。你的创造力应该放在解决问题上,而不是放在制造理解障碍上。
Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.
9. 外部标识符的前六个字符应该是唯一的,尽管这一条很烦人,而且似乎历史悠久,但它可以在你需要在旧的系统上运行程序时,避免你抓狂。
Thy external identifiers shall be unique in the first six characters, though this harsh discipline be irksome and the years of its necessity stretch before thee seemingly without end, lest thou tear thy hair out and go mad on that fateful day when thou desirest to make thy program run on an old system.
10. 你应该与那些声称“全世界都是VAX机”的异端保持距离,不要与他们交往,因为你的程序可能比机器还要长寿。
Thou shalt foreswear, renounce, and abjure the vile heresy which claimeth that ``All the world's a VAX'', and have no commerce with the benighted heathens who cling to this barbarous belief, that the days of thy program may be long even though the days of thy current machine be short.