惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Cyberwarzone
Cyberwarzone
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX
博客园_首页
博客园 - 聂微东
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
T
Tenable Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
A
About on SuperTechFans
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
D
Docker
P
Proofpoint News Feed

博客园 - guoadou

新的开始 《项目管理艺术》读书笔记 —— 决定做什么的常见不良决策一览 《项目管理艺术》读书笔记 —— 项目规划的三种观点 《IF》 - Joseph Rudyard Kipling 论信息系统的架构设计 【转】系统架构设计师考试大纲(2009) nginx error_page 404 用 php header 无法跳转 导出MySQL数据库结构的PHP脚本 轻松面试 搞定技术奇才 Cyworld Values & Principles 通过创建SCHEMABINDING VIEW提高JOIN的速度 长的很像Cyworld的QQ [北京][赛我网]HTML高级工程师 - guoadou - 博客园 [招聘] 韩国企业招聘Java .NET 开发人员 utf8_to_unicode in PHP document.body.scrollTop总是零的原因 unicode_to_utf8 in PHP [新闻]Cyworld.com.cn开始公测 hex2bin in PHP
The Elements of Programming Style
guoadou · 2008-12-23 · via 博客园 - guoadou

The Elements of Programming Style
Brian Kernighan, P. J. Plauger

Introduction
  1. Write clearly - don't be too clever.
Expression
  1. Say what you mean, simply and directly.
  2. Use library functions.
  3. Avoid temporary variables.
  4. Write clearly - don't sacrifice clarity for 'efficiency.'
  5. Let the machine do the dirty work.
  6. Replace repetitive expressions by calls to a common function.
  7. Parenthesize to avoid ambiguity.
  8. Choose variable names that won't be confused.
  9. Avoid the Fortran arithmetic IF.
  10. Avoid unnecessary branches.
  11. Use the good features of a language; avoid the bad ones.
  12. Don't use conditional branches as a substitute for a logical expression.
  13. Use the 'telephone test' for readability.
Control Structure
  1. Use DO-END and indenting to delimit groups of statements.
  2. Use IF-ELSE to emphasize that only one of two actions is to be performed.
  3. Use DO and DO-WHILE to emphasize the presence of loops.
  4. Make your programs read from top to bottom.
  5. Use IF, ELSE IF, ELSE IF, ELSE to implement multi-way branches.
  6. Use the fundamental control flow constructs.
  7. Write first in an easy-to-understand pseudo-language; then translate into whatever language you have to use.
  8. Avoid THEN-IF and null ELSE.
  9. Avoid ELSE GOTO and ELSE RETURN.
  10. Follow each decision as closely as possible with its associated action.
  11. Use data arrays to avoid repetitive control sequences.
  12. Choose a data representation that makes the program simple.
  13. Don't stop with your first draft.
Program Structure
  1. Modularize. Use subroutines.
  2. Make the coupling between modules visible.
  3. Each module should do one thing well.
  4. Make sure every module hides something.
  5. Let the data structure the program.
  6. Don't patch bad code - rewrite it.
  7. Write and test a big program in small pieces.
  8. Use recursive procedures for recursively-defined data structures.
Input and Output
  1. Test input for validity and plausibility.
  2. Make sure input cannot violate the limits of the program.
  3. Terminate input by end-of-file or marker, not by count.
  4. Identify bad input; recover if possible.
  5. Treat end of file conditions in a uniform manner.
  6. Make input easy to prepare and output self-explanatory.
  7. Use uniform input formats.
  8. Make input easy to proofread.
  9. Use free-form input when possible.
  10. Use self-identifying input. Allow defaults. Echo both on output.
  11. Localize input and output in subroutines.
Common Blunders
  1. Make sure all variables are initialized before use.
  2. Don't stop at one bug.
  3. Use debugging compilers.
  4. Initialize constants with DATA statements or INITIAL attributes; initialize variables with executable code.
  5. Watch out for off-by-one errors.
  6. Take care to branch the right way on equality.
  7. Avoid multiple exits from loops.
  8. Make sure your code 'does nothing' gracefully.
  9. Test programs at their boundary values.
  10. Program defensively.
  11. 10.0 times 0.1 is hardly ever 1.0.
  12. Don't compare floating point numbers just for equality.
Efficiency and Instrumentation
  1. Make it right before you make it faster.
  2. Keep it right when you make it faster.
  3. Make it clear before you make it faster.
  4. Don't sacrifice clarity for small gains in 'efficiency.'
  5. Let your compiler do the simple optimizations.
  6. Don't strain to re-use code; reorganize instead.
  7. Make sure special cases are truly special.
  8. Keep it simple to make it faster.
  9. Don't diddle code to make it faster - find a better algorithm.
  10. Instrument your programs. Measure before making 'efficiency' changes.
Documentation
  1. Make sure comments and code agree.
  2. Don't just echo the code with comments - make every comment count.
  3. Don't comment bad code - rewrite it.
  4. Use variable names that mean something.
  5. Use statement labels that mean something.
  6. Format a program to help the reader understand it.
  7. Indent to show the logical structure of a program.
  8. Document your data layouts.
  9. Don't over-comment.

posted on 2008-12-23 13:50  guoadou  阅读(878)  评论()    收藏  举报