# 《编程之道》(小赵译版)（完全）（中）

### DesignBook Three

Thus spake the master programmer:

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

“程序被测试时再去改变它的设计已经太晚了。”

#### 3.1

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.

#### 3.2

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."

#### 3.3

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.

#### 3.4

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?"
“但是我们等不了那么长时间，越快越好，如果10程序员呢？”

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

"And what if I assign a hundred programmers to it?"
“那，100年程序员呢？”

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

### CodingBook Four

Thus spake the master programmer:

"A well-written program is its own heaven;
a poorly-written program is its own hell."
“写的好的程序是它自己的天堂，写的不好的程序是它自己的地狱”

#### 4.1

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.

#### 4.2

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.
“当你的程序正确运行时”。大师说。

#### 4.3

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.
“也在游戏机里？”，初学者又问到。

"It is even in a video game," said the master.
“是的，甚至也存在于游戏机里”。大师说。

"And is the Tao in the DOS for a personal computer?"
“也存在于个人计算机的DOS里吗？”

The master coughed and shifted his position slightly. "The lesson is over for today," he said.

#### 4.4

Price Wang's programmer was coding software. His fingers danced upon the keyboard. The program compiled without an error message, and the program ran like a gentle wind.
###编程大师编写软件时，手指在键盘上快速飞舞。程序编译时没有一条错误信息，程序运行起来就象一阵微风吹过。

Excellent!" the Price exclaimed, "Your technique is faultless!"

"Technique?" said the programmer, turning from his terminal, "What I follow is the Tao -- beyond all technique. When I first began to program I would see before me the whole program in one mass. After three years I no longer saw this mass. Instead, I used subroutines. But now I see nothing. My whole being exists in a formless void. My senses are idle. My spirit, free to work without a plan, follows its own instinct. In short, my program writes itself. True, sometimes there are difficult problems. I see them coming, I slow down, I watch silently. Then I change a single line of code and the difficulties vanish like puffs of idle smoke. I then compile the program. I sit still and let the joy of the work fill my being. I close my eyes for a moment and then log off."
“技巧？”，大师转过身说，“我所遵循的是道--它超乎所有的技巧。当我开始编程时我看到的是整个一大块的程序，三年后我看到的是子过程。现在我什么也看不到了。我的整个存在是没有任何形式的虚无。我感觉很悠闲，总之，事实上是我的程序自己在写，有时我看到一些问题，我看到它们，就停下来静静地观察它们，然后我改变了一行代码，难题就象一阵轻烟一样化为乌有。然后我编译程序。坐在那里享受工作的喜悦。闭了一会眼睛然后退出系统。

Price Wang said, "Would that all of my programmers were as wise!"
“什么时候我的程序员才能都达到这样的境界!”

### MainteanceBook Five

Thus spake the master programmer:

"Though a program be but three lines long, someday it will have to be maintained."
“既使一个程序只有三行长，也总有一天需要去维护它”

#### 5.1

A well-used door needs no oil on its hinges.
A swift-flowing steam does no grow stagnant.
Neither sound nor thoughts can travel through a vacuum.
Software rots if not used.

These are great mysteries.

#### 5.2

A manager asked a programmer how long it would take him to finish the program on which he was working. "I will be finished tomorrow," the programmer promptly replied.

"I think you are being unrealistic," said the manager. "Truthfully, how long will it take?"
“太不着边际了，老实说，要多久？”

The programmer thought for a moment. "I have some features that I wish to add. This will take at least two weeks," he finally said.

"Even that is too much to expect," insisted the manager, "I will be satisfied if you simply tell me when the program is complete."
“即使两个星期恐怕也太夸张了，什么时候你只要告诉我说程序已经完成就好了。”

The programmer agreed to this.

Several years slated, the manager retired. On the way to his retirement lunch, he discovered the programmer asleep at his terminal. He had been programming all night.

#### 5.3

A novice programmer was once assigned to code a simple financial package.

The novice worked furiously for many days, but when his master reviewed his program, he discovered that it contained a screen editor, a set of generalized graphics routines, and artificial intelligence interface, but not the slightest mention of anything financial.

When the master asked about this, the novice became indignant. "Don't be so impatient," he said, "I'll put the financial stuff in eventually."

#### 5.4

Does a good farmer neglect a crop he has planted?
Does a good teacher overlook even the most humble student?
Does a good father allow a single child to starve?
Does a good programmer refuse to maintain his code?

### ManagementBook Six

Thus spake the master programmer:

"Let the programmer be many and the managers few -- then all will be productive."
“增加程序员，减少经理--这样他们都可提高效率。”

#### 6.1

When managers hold endless meetings, the programmers write games. When accountants talk of quarterly profits, the development budget is about to be cut. When senior scientists talk blue sky, the clouds are about to roll in.

Truly, this is not the Tao of Programming.

When managers make commitments, game programs are ignored. When accountants make long-range plans, harmony and order are about to be restored. When senior scientists address the problems at hand, the problems will soon be solved.

Truly, this is the Tao of Programming.

#### 6.2

Why are programmers non-productive? Because their time is wasted in meetings.

Why are programmers rebellious? Because the management interferes too much.

Why are the programmers resigning one by one? Because they are burnt out.

Having worked for poor management, they no longer value their jobs.

#### 6.3

A manager was about to be fired, but a programmer who worked for him invented a new program that became popular and sold well. As a result, the manager retained his job.

The manager tried to give the programmer a bonus, but the programmer refused it, saying, "I wrote the program because I though it was an interesting concept, and thus I expect no reward."

The manager, upon hearing this, remarked, "This programmer, though he holds a position of small esteem, understands well the proper duty of an employee. Lets promote him to the exalted position of management consultant!"

But when told this, the programmer once more refused, saying, "I exist so that I can program. If I were promoted, I would do nothing but waste everyone's time. Can I go now? I have a program that I'm working one."

#### 6.4

A manger went to his programmers and told them: "As regards to your work hours: you are going to have to come in at nine in the morning and leave at five in the afternoon." At this, all of them became angry and several resigned on the spot.

So the manager said: "All right, in that case you may set your own working hours, as long as you finish your projects on schedule." The programmers, now satisfied, began to come in a noon and work to the wee hours of the morning.

• 本文已收录于以下专栏：

举报原因： 您举报文章：《编程之道》(小赵译版)（完全）（中） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)