原创 2001年01月12日 12:52:00

蓝森林 http://www.lslnet.com 2001年1月1日 21:39


The Tao Of Programming —— 编程之道
Translated By Geoffrey James


  本文是<<编程之道>> <<编程之禅>><<计算机时代的寓言>>其中的一册, 由小赵翻译整理, 另外, 这三册书的完整电子文档由小赵根据市面上的<< 编程之道>>一书(包括了上面的三卷)录入整理, 随后将一起刊登(参见《编程之道》全译文)。

Table of Contents 目录

Book 1 -- The Silent Void
Book 2 -- The Ancient Masters
Book 3 -- Design
Book 4 -- Coding
Book 5 -- Maintenance
Book 6 -- Management
Book 7 -- Corporate Wisdom
Book 8 -- Hardware and Software
Book 9 -- Epilogue


The Silent Void
Book One
Thus spake the master programmer:

"When you have learned to snatch the error code from the trap frame, it will be time for you to leave."
Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.
If the Tao is great, then the operating system is great. If the operating system is great, then the compiler is great. If the compiler is greater, then the applications is great. The user is pleased and there is harmony in the world.

The Tao of Programming flows far away and returns on the wind of morning.

The Tao gave birth to machine language. Machine language gave birth to the assembler.
The assembler gave birth to the compiler. Now there are ten thousand languages.

Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao.

But do not program in COBOL if you can avoid it.

In the beginning was the Tao. The Tao gave birth to Space and Time. Therefore, Space and Time are the Yin and Yang of programming.
Programmers that do not comprehend the Tao are always running out of time and space for their programs. Programmers that comprehend the Tao always have enough time and space to accomplish their goals.

How could it be otherwise?

The wise programmer is told about the Tao and follows it. The average programmer is told about the Tao and searches for it. The foolish programmer is told about the Tao and laughs at it.
If it were not for laughter, there would be no Tao.

The highest sounds are the hardest to hear. Going forward is a way to retreat. Greater talent shows itself late in life. Even a perfect program still has bugs.


The Ancient Masters
Book Two
Thus spake the master programmer:

"After three days without programming, life becomes meaningless."

The programmers of old were mysterious and profound. We cannot fathom their thoughts, so all we do is describe their appearance.
Aware, like a fox crossing the water. Alert, like a general on the battlefield. Kind, like a hostess greeting her guests. Simple, like uncarved blocks of wood. Opaque, like black pools in darkened caves.

Who can tell the secrets of their hearts and minds?

The answer exists only in the Tao.

Grand Master Turing once dreamed that he was a machine. When he awoke he exclaimed:

"I don't know whether I am Turing dreaming that I am a machine, or a machine dreaming that I am Turing!"

A programmer from a very large computer company went to a software conference and then returned to report to his manager, saying: "What sort of programmers work for other companies? They behaved badly and were unconcerned with appearances. Their hair was long and unkempt and their clothes were wrinkled and old. They crashed out hospitality suites and they made rude noises during my presentation."
The manager said: "I should have never sent you to the conference. Those programmers live beyond the physical world. They consider life absurd, an accidental coincidence. They come and go without knowing limitations. Without a care, they live only for their programs. Why should they bother with social conventions?"

"They are alive within the Tao."

A novice asked the Master: "Here is a programmer that never designs, documents, or tests his programs. Yet all who know him consider him one of the best programmers in the world. Why is this?"
The Master replies: "That programmer has mastered the Tao. He has gone beyond the need for design; he does not become angry when the system crashes, but accepts the universe without concern. He has gone beyond the need for documentation; he no longer cares if anyone else sees his code. He has gone beyond the need for testing; each of his programs are perfect within themselves, serene and elegant, their purpose self-evident. Truly, he has entered the mystery of the Tao."
经理说:“那个程序员掌握了道。他不需要预先进行设计;系统崩溃时他也从不烦燥,只是接受发生的一切而不管发生的事是好是坏 。他不需要写文档,他从不顾及有没有人看他写的代码。他也不需要进行测试;他写的每个程序都有一个完美的自我,平静而优雅,它们的目的不言自明。他已经真正掌握了道的精髓。”


Book Three
Thus spake the master programmer:

"When program is being tested, it is too late to make design changes."

There once was a man who went to a computer trade show. Each day as he entered, the man told the guard at the door:

"I am a great thief, renowned for my feats of shoplifting. Be forewarned, for this trade show shall not escape unplundered."
This speech disturbed the guard greatly, because there were millions of dollars of computer equipment inside, so he watched the man carefully. But the man merely wandered from booth to booth, humming quietly to himself.

When the man left, the guard took him aside and searched his clothes, but nothing was to be found.

On the next day of the trade show, the man returned and chided the guard saying: "I escaped with a vast booty yesterday, but today will be even better." So the guard watched him ever more closely, but to no avail.

On the final day of the trade show, the guard could restrain his curiosity no longer. "Sir Thief," he said, "I am so perplexed, I cannot live in peace. Please enlighten me. What is it that you are stealing?"
展览会的最后一天,警卫再也不能忍住他的好奇心了。“小偷先生,”他说,“ 你说我惊慌不安,请告诉我,你到底偷了什么?”。

The man smiled. "I am stealing ideas," he said.

There once was a master programmer who wrote unstructured programs. A novice programmer, seeking to imitate him, also began to write unstructured programs. When the novice asked the master to evaluate his progress, the master criticized him for writing unstructured programs, saying: "What is appropriate for the master is not appropriate for the novice. You must understand the Tao before transcending structure."
有一位编程大师,他写非结构化的程序,一位初学者刻意模仿他,也写非结构化的程序。当他让大师看他的进步时,大师批评了他的非结构化程序:“ 对一位编程大师合适的东西未必对一个初学者同样合适,在超越结构化之前,你必须理解编程之道。”
There was once a programmer who was attached to the court of the warlord of Wu. The warlord asked the programmer: "Which is easier to design: an accounting package or an operating system?"
"An operating system," replied the programmer.

The warlord uttered an exclamation of disbelief. "Surely an accounting package is trivial next to the complexity of an operating system," he said.

"Not so," said the programmer, "when designing an accounting package, the programmer operates as a mediator between people having different ideas: how it must operate, how its reports must appear, and how it must conform to the tax laws. By contrast, an operating system is not limited my outside appearances. When designing an operating system, the programmer seeks the simplest harmony between machine and ideas. This is why an operating system is easier to design."

The warlord of Wu nodded and smiled. "That is all good and well, but which is easier to debug?"

The programmer made no reply.

A manager went to the master programmer and showed him the requirements document for a new application. The manager asked the master: "How long will it take to design this system if I assign five programmers to it?"
"It will take one year," said the master promptly.

"But we need this system immediately or even sooner! How long will it take it I assign ten programmers to it?"

The master programmer frowned. "In that case, it will take two years."

"And what if I assign a hundred programmers to it?"

The master programmer shrugged. "Then the design will never be completed," he said.



Book Four
Thus spake the master programmer:

"A well-written program is its own heaven;
a poorly-written program is its own hell."

A program should be light and agile, its subroutines connected like a strings of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little nor too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity.
A program should follow the Law of Least Astonishment. What is this law? It is simply that the program should always respond to the user in the way that astonishes him least.

A program, no matter how complex, should act as a single unit. The program should be directed by the logic within rather than by outward appearances.

If the program fails in these requirements, it will be in a state of disorder and confusion. The only way to correct this is to rewrite the program.

A novice asked the master: "I have a program that sometimes runs and sometimes aborts. I have followed the rules of programming, yet I am totally baffled. What is the reason for this?"
The master replied: "You are confused because you do not understand the Tao. Only a fool expects rational behavior from his fellow humans. Why do you expect it from a machine that humans have constructed? Computers simulate determinism; only the Tao is perfect.

The rules of programming are transitory; only the Tao is eternal. Therefore you must contemplate the Tao before you receive enlightenment."

"But how will I know when I have received enlightenment?" asked the novice.

"Your program will then run correctly," replied the master.

A master was explaining the nature of the Tao to one of his novices, "The Tao is embodied in all software -- regardless of how insignificant," said the master.
"Is the Tao in a hand-held calculator?" asked the novice.

"It is," came the reply.

"Is the Tao in a video game?" continued the novice.


翻阅以前下载的文档,再读这两篇文章,有所感悟,贴。 程序设计之道 第一部寂静虚无篇     大师如是说:“学会从程序抓虫子之后,就可以毕业了。” 1.1节     寂静虚无中有奥秘,不动不静,乃程序之...
  • tiewen
  • tiewen
  • 2014年01月17日 12:10
  • 2124


先写 再去创建需要的类,  #import #import "Student.h" #import "LinkHome.h" #import "WAWJ.h" int main(int argc...
  • blueone009
  • blueone009
  • 2015年12月30日 05:47
  • 132


       数是无形的 ,抽象的概念,它只是人类用来表示数量的一种方法,产物。       为了计数的需要人们发明了十进制(由1到10,这是因为我们有十个手指头)、对于自然界的很多有或者无这种情况如...
  • zxy000678
  • zxy000678
  • 2006年11月28日 06:41
  • 854


指针的基本语法,指针与内存分配,指针在数据结构中的应用 一,指针的语法 指针的意义:我们希望可以通过地址快速的操作变量,因此需要使用指针(地址)。 指针类型变量中存储的地址,即指针变...
  • v_xchen_v
  • v_xchen_v
  • 2016年09月20日 19:23
  • 701

读书笔记 Visual C++ 编程之道

1、switch语句只能接受整形值或者枚举型值 。 2、使用this关键字通过 "->" 运行符来引用类的成员变量。例如类里面的set方法的形参和类的成员变量名称相同,所以用 this代表。 3、子类...
  • u010337503
  • u010337503
  • 2015年04月23日 15:17
  • 200

Python黑帽子--黑客与渗透测试编程之道 python3 实现代码

最近在看 Python黑帽子–黑客与渗透测试编程之道 这本书 发现这本书的代码实现都是使用python2 的于是我就想使用python3来实现 缓慢更新中 python2版本 有一个博主写的特别好...
  • qq_39038028
  • qq_39038028
  • 2017年06月04日 17:15
  • 532


 前言  《编程之道》的出版在程序设计业内得到了普遍的接受,出版社邀请我翻译一些与之相关的文章,以作为那部著名的经典之作的补充。虽然,我申明我的能力难以胜任,但我最终还是被说服试一试。  本书是许多个...
  • BlackEagle_
  • BlackEagle_
  • 2006年02月16日 20:18
  • 6026

七月算法机器学习笔记8 聚类算法

七月算法(http://www.julyedu.com) 12月份 机器学习在线班 学习笔记
  • jieke2008
  • jieke2008
  • 2016年04月07日 18:57
  • 1095


第一章 kali虚拟机 开始用pip安装github3.py,没什么问题 跟着安装WingIDE,下载linux对应位数的版本的deb,就行了,但是产生了依赖 于是修改软件源APT-sourc...
  • u012763794
  • u012763794
  • 2016年01月30日 23:01
  • 31561

iOS书摘之Objective-C编程之道 iOS设计模式解析

来自《Objective-C编程之道iOS设计模式解析》一书的摘要总结   一、Prototype 原型模式 定义:使用原型实例指定创建对象的种类,并通过复制这个原型创建新的对象。(《设计模...
  • qq_19924881
  • qq_19924881
  • 2017年07月11日 09:42
  • 103