Gangmax Blog

The philosophy of Unix

I think it’s not only the philosophy of Unix, but also the philosophy of software development.

英文原文来自http://coolshell.cn/articles/2324.html,我自己翻译成了中文。

总则

  1. Everything (including hardware) is a file. 一切(包括硬件)都是文件。

  2. Configuration data stored in text. 以文本形式储存配置数据。

  3. Small, single-purpose program. 小而功能单一的程序。

  4. Avoid captive user interfaces. 避免令人困惑的用户接口。

  5. Ability to chain program together to perform complex tasks. 拥有将多个程序串联起来以执行复杂任务的能力。

Douglas McIlroy是认为UNIX的哲学是这样的:

  1. Write programs that do one thing and do it well. 写只做一件事、并且把它做好的程序。

  2. Write programs to work together. 让不同程序可以在一起交互工作。

  3. Write programs to handle text streams, because that is a universal interface. 尽可能地让程序处理文本流,因为它是最通用的接口。

“The Art of Unix Programming” (Eric Steven Raymond):

  1. Rule of Modularity: Write simple parts connected by clean interfaces. 模块化原则:将简单的部分用简洁的接口连接。

  2. Rule of Clarity: Clarity is better than cleverness. 清晰原则:清晰胜过巧妙。

  3. Rule of Composition: Design programs to be connected to other programs. 组合原则:在设计程序时就需要考虑它会与其它程序交互工作。

  4. Rule of Separation: Separate policy from mechanism; separate interfaces from engines. 隔离原则:将具体策略从实现机制中分离,将接口从核心中分离。

  5. Rule of Simplicity: Design for simplicity; add complexity only where you must. 简单原则:设计应该以简单为目标,只有在必须复杂的情况下增加复杂性。

  6. Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do. 节俭原则:只有在被证明无法写出“小”程序的情况下才写“大”程序。

  7. Rule of Transparency: Design for visibility to make inspection and debugging easier. 透明原则:为能见度而设计,以使检视和查错更容易。

  8. Rule of Robustness: Robustness is the child of transparency and simplicity. 健壮性原则:健壮性是透明和简单的结果。

  9. Rule of Representation: Fold knowledge into data so program logic can be stupid and robust. 表现原则:将知识用数据的方式来表达,这样程序的逻辑就可以既简单又健壮。

  10. Rule of Least Surprise: In interface design, always do the least surprising thing. 最小意外原则:在接口设计中,总是做最小意外的事情。

  11. Rule of Silence: When a program has nothing surprising to say, it should say nothing. 沉默原则:如果一个程序没有意外的事情要表达,它就别表达。

  12. Rule of Repair: When you must fail, fail noisily and as soon as possible. 修复原则(快速故障原则):如果程序一定要出现故障,要让它尽快、尽可能明显的出现故障。

  13. Rule of Economy: Programmer time is expensive; conserve it in preference to machine time. 经济性原则:程序员的时间很昂贵,尽可能用编程的方式让机器完成工作。

  14. Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.(代码)生成原则:在可能的情况下,避免手工创建代码,用程序来生成程序。

  15. Rule of Optimization: Prototype before polishing. Get it working before you optimize it. 优化原则:先制作原型后抛光。先让其工作再对其优化。

  16. Rule of Diversity: Distrust all claims for “one true way”. 多样性原则:怀疑所有“真理只有一种”的说法。

  17. Rule of Extensibility: Design for the future, because it will be here sooner than you think. 扩展性原则:为未来而设计,因为它会比你想象的来得更快。

X Windows 的设计者 Mike Gancarz 给出了下面九条哲学思想:

  1. Small is beautiful. 小就是美。

  2. Make each program do one thing well. 让每一个程序做一件事情并且做好。

  3. Build a prototype as soon as possible. 尽快建立原型。

  4. Choose portability over efficiency. 可移植性重于效率。

  5. Store data in flat text files. 将数据保存为纯文本文件。

  6. Use software leverage to your advantage. 用软件促进你的优势。

  7. Use shell scripts to increase leverage and portability. 用shell脚本提升杠杆率和可移植性。

  8. Avoid captive user interfaces. 避免令人困惑的用户接口。

  9. Make every program a filter. 让每个程序都成为过滤器。

Comments