More Programming Pearl (编程珠玑)名句大赏
一、编码
| 中文 | 英文 |
|---|---|
| 如果还没想清楚,就用蛮力算法。——Ken Thompson | When in doubt, use brute force. ——Ken Thompson |
| 不要使用反正弦和反余弦函数——你总能用优美的恒等式,或者是计算向量点积来更好地解决问题。—— Jim Conyngham | Avoid arc-sine and arc-cosine functions - you can usually do better by applying a trig identity or computing a vector dot-product. —— Jim Conyngham |
| 在存储日期中的年份的时候,请使用四位数字。—— David Martin | Allocate four digits for the year part of a date: a new millennium is coming.—— David Martin |
| 避免使用不对称结构。—— Andy Huber | Avoid asymmetry.—— Andy Huber |
| 代码写的越急,程序跑得越慢。—— Roy Carlson | The sooner you start to code, the longer the program will take. —— Roy Carlson |
| 你用英语都写不出来的东西就别指望用代码写了。—— Peter Halpern | If you can't write it down in English, you can't code it. —— Peter Halpern |
| 如果代码和注释不一致,那很可能两者都错了。—— Norm Schryer | If the code and the comments disagree, then both are probably wrong. —— Norm Schryer |
| 如果你发现特殊情况太多,那你肯定是用错方法了。—— Craig Zerouni | If you have too many special cases, you are doing it wrong. —— Craig Zerouni |
| 先把数据结构搞清楚,程序的其余部分自现。—— David Jones | Get your data structures correct first, and the rest of the program will write itself. —— David Jones |
二、用户界面
| 中文 | 英文 |
|---|---|
| 尽可能让用户界面风格保持一致和可预测。—— 匿名用户 | [The Principle of Least Astonishment] Make a user interface as consistent and as predictable as possible. —— Contributed by several readers |
| 计算机生成的输入通常会让一个原本设计接受手工输入的程序不堪重负。—— Dennis Ritchie | A program designed for inputs from people is usually stressed beyond the breaking point by computer-generated inputs. —— Dennis Ritchie |
| 手工填写的表单里有20%都包含坏数据。—— Vic Vyssotsky | Twenty percent of all input forms filled out by people contain bad data. —— Vic Vyssotsky |
| 80%的表单会要你回答没有必要的问题。—— Mike Garey | Eighty percent of all input forms ask questions they have no business asking. —— Mike Garey |
| 不要让用户提供那些系统已经知道的信息。—— Rick Lemons | Don‘t make the user provide information that the system already knows. —— Rick Lemons |
| 所有数据集的80%中,有95%的信息量都可以用清晰的图表示。—— William Cleveland | For 80% of all data sets, 95% of the information can be seen in a good graph. —— William S. Cleveland |
三、调试
| 中文 | 英文 |
|---|---|
| 在我所有的程序错误中,80%是语法错误,剩下20%里,80%是简单的逻辑错误,在剩下4%里,80%是指针错误,只有余下的0.8%才是困难的问题。—— Marc Donner | Of all my programming bugs, 80% are syntax errors. Of the remaining 20%, 80% are trivial logical errors. Of the remaining 4%, 80% are pointer errors. And the remaining 0.8% are hard. —— Marc Donner |
| 在系统测试阶段找出并修正错误,要比开发者自己完成这一工作多付出2倍的努力。而当系统已经交付使用之后找出并修正错误,要比系统测试阶段多付出9倍的努力。因此,请坚持让开发者进行单元测试吧。—— Larry Bernstain | It takes three times the effort to find and fix bugs in system test than when done by the developer. It takes ten times the effort to find and fix bugs in the field than when done in system test. Therefore, insist on unit tests by the developer. —— Larry Bernstein |
| 不要站着调试程序,那会使得你的耐心减半,你需要的是全神贯注。—— Dave Storer | Don‘t debug standing up. It cuts your patience in half, and you need all you can muster. —— Dave Storer |
| 别在注释里陷得太深——注释很可能会误导你,你要调试的只是代码。—— Dave Storer | Don‘t get suckered in by the comments – they can be terribly misleading. Debug only the code. —— Dave Storer |
| 测试只能证明程序有错误,而不能证明程序没有错误。—— Edsger Dijkstra | Testing can show the presence of bugs, but not their absence. —— Edsger W. Dijkstra |
| 新系统的每一个新用户都可能发现一类新的错误。—— Brian Kernighan | Each new user of a new system uncovers a new class of bugs. —— Brian Kernighan |
| 东西没坏,就别乱修。 —— Ronald Reagan | If it ain‘t broke, don’t fix it. —— Ronald Reagan |
| 如果我们没能力修好它,我们就会告诉你它根本没坏。—— Walt Weir | [The Maintainer‘s Motto] If we can’t fix it, it ain‘t broke. —— Lieutenant Colonel Walt Weir |
| 修正程序错误的第一步是要重现这个错误。—— Tom Duff | The first step in fixing a broken program is getting it to fail repeatably. —— Tom Duff |
四、性能
| 中文 | 英文 |
|---|---|
| 程序优化第一法则:不要优化。程序优化第二法则:还是不要优化。—— Michael Jackson | [The First Rule of Program Optimization] Don‘t do it. [The Second Rule of Program Optimization – For experts only.] Don’t do it yet. —— Michael Jackson |
| 对于那些快速算法,我们总是可以拿一些速度差不多但是更容易理解的算法来替代它们。—— Douglas Jones | The fastest algorithm can frequently be replaced by one that is almost as fast and much easier to understand. —— Douglas W. Jones |
| 在一些机器上,间接寻址比基址寻址要慢,所以请把结构体或者记录中最常用的成员放在最前面。—— Mike Morton | On some machines indirection is slower with displacement, so the most-used member of a structure or a record should be first. —— Mike Morton |
| 在一个非IO密集型程序中,超过一半的运行时间是花在不足4%的代码上的。—— Don Knuth | In non-I/O-bound programs, less than four per cent of a program generally accounts for more than half of its running time. —— Don Knuth |
| 在优化一个程序之前,请先用性能监视工具找到程序的“热点”。—— Mike Morton | Before optimizing, use a profiler to locate the “hot spots” of the program. —— Mike Morton |
| 当你为了加速,把一页代码变成几条简单的指令时,请不要忘了增加注释,以使源码的行数保持为一个常量。—— Mike Morton | [Conservation of Code Size] When you turn an ordinary page of code into just a handful of instructions for speed, expand the comments to keep the number of source lines constant. —— Mike Morton |
| 如果程序员自己模拟实现了一个构造比编译器本身实现的那个构造还要快,那编译器的作者也太失败了。—— Guy Steele | If the programmer can simulate a construct faster than the compiler can implement the construct itself, then the compiler writer has blown it badly. —— Guy L. Steele, Jr. |
| 要加速一个IO密集型程序,请首先考虑所有的IO,消除那些不必要的或冗余的IO,并使余下的部分尽可能地块。—— David Martin | To speed up an I/O-bound program, begin by accounting for all I/O. Eliminate that which is unnecessary or redundant, and make the remaining as fast as possible. —— David Martin |
| 最快的IO就是不IO。—— Nils-Peter Nelson | The fastest IO is no IO. —— Nils-Peter Nelson |
| 那些最便宜、最快而且可靠性最高的计算机组件压根就不存在。—— Gordon Bell | The cheapest, fastest and most reliable components of a computer system are those that aren‘t there. —— Gordon Bell |
| 把一个本来就错了的程序变得更糟糕绝不是你的错。—— Bill McKeeman | [Compiler Writer’s Motto – Optimization Pass] Making a wrong program worse is no sin. —— Bill McKeeman |
| Lisp程序员知道所有东西的值,却不知道那些东西的计算成本。—— Alan Perlis | Lisp programmers know the value of everything but the cost of nothing. —— Alan Perlis |
五、文档
| 中文 | 英文 |
|---|---|
| 如果一句话反过来就必然不成立,那就根本没必要把这句话放进文档。—— Bob Martin | [The Test of Negation] Don‘t include a sentence in documentation if its negation is obviously false. —— Bob Martin |
| 当你试图解释一条命令、一个语言特性或者是一种硬件的时候,请首先说明它要解决什么问题。 —— David Martin | When explaining a command, or language feature, or hardware widget, first describe the problem it is designed to solve. —— David Martin |
| 一个 { 规格说明、设计、过程、测试计划 } 如果不能在一页A4纸上写明白,那么这个东西别人就没法理解。—— Mark Ardis | [One Page Principle] A {specification, design, procedure, test plan} that will not fit on one page of 8.5-by-11 inch paper cannot be understood. —— Mark Ardis |
| 纸上的工作没结束,整个工作也就还没结束。—— 匿名 | The job‘s not over until the paperwork’s done. —— Anon |
六、软件管理
| 中文 | 英文 |
|---|---|
| 系统的结构反映出构建该系统的组织的结构。—— Richard Fairley | The structure of a system reflects the structure of the organization that built it. —— Richard E. Fairley |
| 别坚持做没用的事情。—— 匿名 | Don‘t keep doing what doesn’t work. —— Anon |
| 前90%的代码占用了90%的预定开发时间,余下的10%代码又花费了90%的预定开发时间。——Tom Cargill | [Rule of Credibility] The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. —— Tom Cargill |
| 只有不到10%的代码用于完成这个程序表面上的目的,余下的都在处理输入输出、数据验证、数据结构维护等家务活。—— Mary Shaw | Less than 10% of the code has to do with the ostensible purpose of the system; the rest deals with input-output, data validation, data structure maintenance, and other housekeeping. —— Mary Shaw |
| 正确的判断来源于经验,然而经验来源于错误的判断。—— Fred Brooks | Good judgement comes from experience, and experience comes from bad judgement. —— Fred Brooks |
| 如果有人基本上做出了你想要的东西,你就没必要自己写一个新程序,就算你非写不可,也请尽可能地利用现有的代码。—— Richard Hill | Don‘t write a new program if one already does more or less what you want. And if you must write a program, use existing code to do as much of the work as possible. —— Richard Hill |
| 代码能借用就借用。—— Tom Duff | Whenever possible, steal code. —— Tom Duff |
| 与客户保持良好的关系可以使生产率加倍。—— Larry Bernstain | Good customer relations double productivity. —— Larry Bernstein |
| 把一个现有成熟程序转移到一种新语言或者新平台,只需要原来开发的十分之一的时间、人力、成本。—— Douglas Jones | Translating a working program to a new language or system takes ten percent of the original development time or manpower or cost. —— Douglas W. Jones |
| 那些用手做就很快了的事情,就不要用计算机去做了。—— Richard Hill | Don‘t use the computer to do things that can be done efficiently by hand. —— Richard Hill |
| 那些能用计算机迅速解决的问题,就别用手做了。—— Tom Duff | Don’t use hands to do things that can be done efficiently by the computer. —— Tom Duff |
| 我想写的不只是程序,而且是会写程序的程序。—— Dick Sites | I‘d rather write programs to write programs than write programs. —— Dick Sites |
| 计划好抛弃一个原型,这是迟早的事情。—— Fred Brooks | [Brooks’s Law of Prototypes] Plan to throw one away, you will anyhow. —— Fred Brooks |
| 如果开始就打算抛弃一个原型,那恐怕你得抛弃两个。—— Craig Zerouni | If you plan to throw one away, you will throw away two. —— Craig Zerouni |
| 原型方法可以将系统开发的工作量减少40%。—— Larry Bernstain | Prototyping cuts the work to produce a system by 40%. —— Larry Bernstein |
| 拼命干活无法取代理解。—— H. H. Williams | Furious activity is no substitute for understanding. —— H. H. Williams |
| 永远先做难的部分。如果难的部分是不可能的,何必在简单的部分上浪费时间?一旦难的部分完成,你就畅通无阻了。 | Always do the hard part first. If the hard part is impossible, why waste time on the easy part? Once the hard part is done, you‘re home free. |
| 永远先做简单的部分。起初你认为简单的部分常常会变成难的部分。一旦简单的部分完成了,你就可以集中全部精力攻克难的部分。 | Always do the easy part first. What you think at first is the easy part often turns out to be the hard part. Once the easy part is done, you can concentrate all your efforts on the hard part. |

浙公网安备 33010602011771号