Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > IT > IT人生 > The Tao of Programming > Book 4 - Coding

Book 4 - Coding

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

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

尝有程序员为价格王编程。手之所触,击键騞然,莫不中音:合于《桑林》之舞,乃中《经首》之会。程序编译而无误,运行如三月之风。

王曰:“嘻,善哉!技盖至此乎?”

程序员面终端,转而对曰:“吾之所好者,道也;进乎技矣。始吾之编程之时,所见无非程序者;三年之后,因函数故,未尝见全程序也。方今之时,吾以神遇而不以目视,官知止而神欲行。依乎天理,无需计划,因其固然,吾未尝编程而程序自书焉。虽然,每至于难解处,吾见其难为,怵然为戒,视为止,行为迟。击键甚微,豁然已解,如土委地。编译程序,抚键而坐,为之踌躇满志,闭目而登出之。”

王曰:“善哉!吾闻子之言,得悟焉。”