編程之道(完全小趙譯版)上輯
發(fā)表時(shí)間:2024-02-26 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]《編程之道》(小趙譯版) 藍(lán)森林 http://www.lslnet.com 2001年1月1日 21:39The Tao Of Programming —— 編程之道Translated By Geoffrey James[小趙(slimzhao@21cn.com)]翻譯整理說(shuō)明: 本文是&l...
《編程之道》(小趙譯版) 藍(lán)森林 http://www.lslnet.com 2001年1月1日 21:39
The Tao Of Programming —— 編程之道
Translated By Geoffrey James
[小趙(slimzhao@21cn.com)]翻譯整理
說(shuō)明:
本文是<<編程之道>> <<編程之禪>><<計(jì)算機(jī)時(shí)代的寓言>>其中的一冊(cè), 由小趙翻譯整理, 另外, 這三冊(cè)書的完整電子文檔由小趙根據(jù)市面上的<< 編程之道>>一書(包括了上面的三卷)錄入整理, 隨后將一起刊登(參見(jiàn)《編程之道》全譯文)。
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:
編程大師如是說(shuō):
"When you have learned to snatch the error code from the trap frame, it will be time for you to leave."
“當(dāng)你從我手中奪走水晶球時(shí),就是你離開的時(shí)候了!
1.1
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.
如果道是完美的,那么操作系統(tǒng)就是完美的,如果操作系統(tǒng)是完美的,那么編譯囂就是完美的,如果編譯囂是完美的,那么應(yīng)用程序就是完美的,所以用戶心滿意足,整個(gè)世界因此和諧。
The Tao of Programming flows far away and returns on the wind of morning.
編程之道去如黃鶴來(lái)如晨風(fēng)。
1.2
The Tao gave birth to machine language. Machine language gave birth to the assembler.
道生機(jī)器語(yǔ)言,機(jī)器語(yǔ)言生匯編囂。
The assembler gave birth to the compiler. Now there are ten thousand languages.
匯編器生編譯器,最后產(chǎn)生上萬(wàn)種高級(jí)語(yǔ)言。
Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao.
不論多么的微不足道,每種語(yǔ)言都有它自己的目的,每種語(yǔ)言都表達(dá)了軟件的陰陽(yáng)兩極。每種語(yǔ)言都各得其道。
But do not program in COBOL if you can avoid it.
但是盡量不要用COBOL語(yǔ)言。
1.3
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.
道之初,帶來(lái)了空間和時(shí)間,所以,空間和時(shí)間是編程的陰陽(yáng)兩極。
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.
不懂編程之道的程序員常常把空間和時(shí)間消耗殆盡,得道的程序員則總是有足夠的空間和時(shí)間去完成編程任務(wù)。
How could it be otherwise?
否則會(huì)是什么樣呢?
1.4
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.
上士聞道,從而行之。中士聞道,謹(jǐn)而尋之。下士聞道,大笑之。
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.
希音不聞,進(jìn)即是退,大囂晚成。任何程序都有漏洞。
The Ancient Masters
Book Two
Thus spake the master programmer:
編程大師如是說(shuō):
"After three days without programming, life becomes meaningless."
三日不編程,食肉無(wú)味。
2.1
The programmers of old were mysterious and profound. We cannot fathom their thoughts, so all we do is describe their appearance.
遠(yuǎn)古時(shí)代的編程大師們高深莫測(cè),我們不能揣測(cè)他們的所思所想,只能描述外表所見(jiàn)。
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.
他達(dá)明,如狐貍過(guò)水;機(jī)警,如戰(zhàn)場(chǎng)上的將軍;和善,如主婦款待客人;簡(jiǎn)單,呆若木雞;混沌,如深淵之水。
Who can tell the secrets of their hearts and minds?
誰(shuí)能道盡他們的所有?
The answer exists only in the Tao.
答案僅存于道。
2.2
Grand Master Turing once dreamed that he was a machine. When he awoke he exclaimed:
超級(jí)大師圖靈曾夢(mèng)見(jiàn)自己是一臺(tái)機(jī)器,醒后他這樣回憶:
"I don't know whether I am Turing dreaming that I am a machine, or a machine dreaming that I am Turing!"
“我不知道是圖靈夢(mèng)見(jiàn)自己變成機(jī)器還是機(jī)器夢(mèng)見(jiàn)自己變成圖靈!
2.3
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."
一個(gè)大公司的程序員參加一個(gè)軟件會(huì)議后向他的主管匯報(bào):“那些別的公司的程序員都是些什么樣的人呀?他們舉止不雅,不修邊幅,頭發(fā)蓬亂,衣服破舊,根本不熱情好客,還在我說(shuō)話的時(shí)候亂嚷嚷!
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?"
他的主管說(shuō):“我不應(yīng)該讓你參加這次會(huì)議,這些程序員生活在現(xiàn)實(shí)世界之外。他們認(rèn)為生活是可笑的,一場(chǎng)意外的偶然而已。他們來(lái)去自由,無(wú)所牽掛,他們只為他們的程序生活。為什么要用世俗的煩擾去擾亂他們呢?”
"They are alive within the Tao."
“他們生活在道中”。
2.4
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?"
一個(gè)初學(xué)者問(wèn)主管經(jīng)理:“有一個(gè)程序員,他從來(lái)不預(yù)先設(shè)計(jì),也不寫文檔,甚至不測(cè)試他的程序,但是知道他的人都認(rèn)為他是世界上最偉大的程序員,為什么呢?”
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."
經(jīng)理說(shuō):“那個(gè)程序員掌握了道。他不需要預(yù)先進(jìn)行設(shè)計(jì);系統(tǒng)崩潰時(shí)他也從不煩燥,只是接受發(fā)生的一切而不管發(fā)生的事是好是壞 。他不需要寫文檔,他從不顧及有沒(méi)有人看他寫的代碼。他也不需要進(jìn)行測(cè)試;他寫的每個(gè)程序都有一個(gè)完美的自我,平靜而優(yōu)雅,它們的目的不言自明。他已經(jīng)真正掌握了道的精髓。”
Design
Book Three
Thus spake the master programmer:
編程大師如是說(shuō):
"When program is being tested, it is too late to make design changes."
“程序被測(cè)試時(shí)再去改變它的設(shè)計(jì)已經(jīng)太晚了。”
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:
曾經(jīng)有一個(gè)人參加計(jì)算機(jī)展覽,每天他進(jìn)門時(shí)都對(duì)門衛(wèi)說(shuō):
"I am a great thief, renowned for my feats of shoplifting. Be forewarned, for this trade show shall not escape unplundered."
“先警告你,我是偷盜高手,我入室偷盜的本領(lǐng)聞名遐邇。這次展覽會(huì)也再劫難逃。”
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.
警衛(wèi)因此大動(dòng)干戈,因?yàn)槔锩嬗袃r(jià)值百萬(wàn)的計(jì)算機(jī)設(shè)備,所以他牢牢盯緊了這個(gè)人,但是這個(gè)人只是從一個(gè)攤位逛到另一個(gè)攤位,一邊平靜地喃喃自語(yǔ)。
When the man left, the guard took him aside and searched his clothes, but nothing was to be found.
當(dāng)這個(gè)人離開時(shí),警衛(wèi)搜了他的身,但是什么也沒(méi)有發(fā)現(xiàn)。
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.
展覽會(huì)的第二天,這個(gè)人又對(duì)警衛(wèi)說(shuō):“昨天我滿載而歸,但是今天我會(huì)收獲更大!彼跃l(wèi)更加小心地盯緊他,但是這樣做完全于事無(wú)補(bǔ)。
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?"
展覽會(huì)的最后一天,警衛(wèi)再也不能忍住他的好奇心了。“小偷先生,”他說(shuō),“ 你說(shuō)我驚慌不安,請(qǐng)告訴我,你到底偷了什么?”。
The man smiled. "I am stealing ideas," he said.
這個(gè)人笑笑說(shuō):“我在偷想法!
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."
有一位編程大師,他寫非結(jié)構(gòu)化的程序,一位初學(xué)者刻意模仿他,也寫非結(jié)構(gòu)化的程序。當(dāng)他讓大師看他的進(jìn)步時(shí),大師批評(píng)了他的非結(jié)構(gòu)化程序:“ 對(duì)一位編程大師合適的東西未必對(duì)一個(gè)初學(xué)者同樣合適,在超越結(jié)構(gòu)化之前,你必須理解編程之道!
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?"
###有人問(wèn)一位程序員,“一個(gè)財(cái)務(wù)軟件和一個(gè)操作系統(tǒng)哪個(gè)更容易設(shè)計(jì)?”
"An operating system," replied the programmer.
“是操作系統(tǒng)”,這位程序員回答說(shuō)。
The warlord uttered an exclamation of disbelief. "Surely an accounting package is trivial next to the complexity of an operating system," he said.
此人大惑不解。他說(shuō):“顯然一個(gè)財(cái)務(wù)軟件比起操作系統(tǒng)來(lái)說(shuō)其復(fù)雜性是微不足道的”。
"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."
程序員說(shuō):“不,設(shè)計(jì)財(cái)務(wù)軟件時(shí),一個(gè)程序員必須成為持不同意見(jiàn)的用戶與計(jì)算機(jī)的一個(gè)中介,他必須了解用戶的操作習(xí)慣,報(bào)表要是什么形式,如何遵循稅法。相反,一個(gè)操作系統(tǒng)完全與這些外部的東西無(wú)關(guān)。設(shè)計(jì)操作系統(tǒng),程序員只需要達(dá)到自己的設(shè)想與機(jī)器之間的簡(jiǎn)單的和諧。這就是為什么操作系統(tǒng)反而比財(cái)務(wù)軟件更容易設(shè)計(jì)!
The warlord of Wu nodded and smiled. "That is all good and well, but which is easier to debug?"
這些人笑著說(shuō)!安诲e(cuò),但是哪一個(gè)更容易調(diào)試呢?”
The programmer made no reply.
程序員沒(méi)有回答。
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?"
一個(gè)項(xiàng)目經(jīng)理帶給編程大師一個(gè)項(xiàng)目的需求,然后問(wèn)大師:“如果我給你5個(gè)程序員,要多少時(shí)間設(shè)計(jì)這個(gè)項(xiàng)目?”
"It will take one year," said the master promptly.
“一年”,大師說(shuō)。
"But we need this system immediately or even sooner! How long will it take it I assign ten programmers to it?"
“但是我們等不了那么長(zhǎng)時(shí)間,越快越好,如果10程序員呢?”
The master programmer frowned. "In that case, it will take two years."
大師皺了一下眉頭說(shuō):“那就要花2年”。
"And what if I assign a hundred programmers to it?"
“那,100年程序員呢?”
The master programmer shrugged. "Then the design will never be completed," he said.
大師聳了聳肩說(shuō):“那這個(gè)項(xiàng)目就永遠(yuǎn)完不成了!
Coding
Book Four
Thus spake the master programmer:
編程大師如是說(shuō):
"A well-written program is its own heaven;
a poorly-written program is its own hell."
“寫的好的程序是它自己的天堂,寫的不好的程序是它自己的地獄”