Brian Kernighan's Programming Style Tips

[list]
[*] Say what you mean, simply and directly.
[*] Use the ``telephone test'' for readability.
[*] Write clearly - don't be too clever.
[*] Don't use conditional expressions as a substitute for a logical expression.
[*] Parenthesize to avoid ambiguity.
[*] Each time you make a test, do something.
[*] Follow each decision as closely as possible with its associated action.
[*] Use the good features of a language; avoid the bad ones.
[*] Capture regularity in control flow, irregularity in data.
[*] Each module should do one thing well.
[*] Make sure comments and code agree.
[*] Don't just echo the code with comments - make every comment count.
[*] Don't comment bad code - rewrite it.
[*] Use symbolic constants for magic numbers.
[*] Watch out for side effects and order of evaluation.
[*] Macros are not functions.
[*] Watch out for off-by-one errors.
[*] Test programs at their boundaries.
[*] Program defensively.
[*] Make sure input cannot violate the limits of the program.
[*] Make it right before you make it faster.
[*] Keep it right when you make it faster.
[*] Don't sacrifice clarity for small gains in ``efficiency.''
[*] Don't stop with your first draft.
[/list]
[From The Elements of Programming Style, Kernighan & Plauger, McGraw-Hill, 1978]
Note: this book is still well worth reading- even though most of the examples are in languages that you probably haven't heard of, the principles are universal. -DJE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值