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.
有物混成,先天地生。致虚极,守静笃,静若处子,动若脱兔,可以为程序母。吾不知其名,字之曰道。
道大,OS大,compiler大,app亦大。用户喜之,天地和谐。
道,去若飞鹤来若晨风。
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.
道生机语,机语生汇编,汇编生compiler,compiler生程序。
程序负阴而抱阳,冲气以为和,各得其道。
勿用COBOL。
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.
上士闻道,勤而行之;中士闻道,勤而寻之;下士闻道,大笑之。
不笑不足以为道。
大音希声,进道若退,大器晚成,大程亦错。
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."
大社之人与大会,返,语于manager曰:『其程序员者,何类也?行无礼让,言无信雅,发无结束,衣无洁整。待客无法,扰我言辞。』
曰:『不当使汝往之。其程序员者,游离于天地。嘲戏生命,视之偶遇。去来随性,无所挂牵。其命在于程序,汝何以世之准绳责之?』
『其命在于道。』
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."
或问曰:『有程序员未尝design、document、test其程序,然天下皆谓其程序美于天下,何也?』
曰:『得道。其无design,遇crash,不怒,顺乎天常;其无documentation,或视其程序,不念;其无testing,程序极美,优哉雅哉,不言自明。信夫!入道也!』
Thus spake the master programmer:
"When program is being tested, it is too late to make design changes."
师曰:『及其test时改之,晚矣!』
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.
尝有人与机展,每进,语于guard曰:
『我,贼也,工于行窃。汝将警之,此展在劫难逃。』
Guard大窘,防范甚严。然其人悠然自得,往来于展位间,喃喃然若自语。
待其离展,guard搜其身,终不能得一物。
次日,其人返之,斥guard曰:『昨日,吾所获甚丰,今日更甚。』Guard监之愈甚,仍不能得。
及展终,guard问曰:『余之惑甚矣。何物乃先生所盗?』
笑曰:『思想也。』
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.
尝有程序员见于吴王。王问曰:『设计会计软件,设计操作系统,孰易?』
曰:『操作系统。』
王不之信,曰:『会计软件易于操作系统,诚然!』
曰:『非也。夫设计会计软件,程序员者,各色用户之中介也,其思多异。及其操作系统,程序员者,但求机器于思想之和谐也。此之谓设计操作系统易也。』
吴王颔而笑曰:『debug,二者孰易?』
程序员默而不应。
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.
Manager见主程序员,以新application之requirements document示之,问曰:『今有程序员五人,需时日几何?』
曰:『一年。』
曰:『吾急需之!若有十人,几何?』
颦然曰:『二年。』
曰:『百人若何?』
对曰:『万世。』
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.
"It is even in a video game," said the master.
"And is the Tao in the DOS for a personal computer?"
The master coughed and shifted his position slightly. "The lesson is over for today," he said.
师释道,曰:『道者遍及软件,无论大小。』
问曰:『计算器者有道欤?』
曰:『有道。』
问曰:『游戏机者有道欤?』
曰:『然也。』
问曰:『PC之DOS者有道欤?』
师咳而转身曰:『课止与此。』
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!"
程序员为公子王写软件,指飞键舞,不差丝毫,行之如风。
公子王曰:『嘻,善哉!技盖至此乎?』
程序员释键对曰:『臣之所好者道也,进乎技矣。始臣之编程之时,所见无非程序者;三年之后,未尝见程序也,见其子程序也;方今之时,臣以神遇而不以目视,官知止而神欲行,因其固然,程序自写之。诚然,尝至于难者,吾见其难为,怵然为戒,视为止,行为迟,改其一字,謋然已解,如烟随风。使之编译,释键而坐,为之踌躇满志,闭目而log off之。』
公子王曰:『吾之程序员皆如此,则其善焉!』
Thus spake the master programmer:
"Though a program be but three lines long, someday it will have to be maintained."
师曰:『程序虽短,终将修之。』
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.
户枢不蠹。
流水不腐。
声、意止于虚空。
软件朽于不用。
此之谓大神秘。
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.
Manager问其程序员,何日以完工。员旋对曰:『来日。』
Manager曰:『欺也。以君之诚言,何日?』
员思之,稍顷,曰:『吾欲使之多能,十五日方可完工。』
Manager曰:『彼者亦不可信。待程序完工之日,愿君语我。』
应之。
经岁,manager将退隐。及retirement lunch中,始见程序员睡于终端前,其彻夜编程矣。
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."
或忙于财务软件。
其操劳数日,师视之,见屏幕编辑器、图形子程序、AI界面,惟不见财务。
师惑之。其怒对曰:『甚矣,汝之无忍。吾将置之于其末。』
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?
耕者岂有不事其稼者乎?
师者岂有不问其弟子者乎?
父者岂有不食其子者乎?
程序员者岂有不修其code者乎?