轉載:編 程 之 道 The Tao Of Programming
Geoffrey James
第一篇 靜寂的空宇
第二篇 古代的大師
第三篇 設計
第四篇 編碼
第五篇 維護
第六篇 管理
第七篇 公司里的學問
第八篇 硬件和軟件
第九篇 尾聲
第一篇 靜寂的空宇
編程大師如是說:
“當你有本事奪走我手中的這塊水晶石時,就是你出師的時侯了。”
1.1
在靜寂的空宇里,一種神奇的物質形成并誕生了。它立刻便靜止了,獨自守侯著,豪無動靜,然而又處于永恒的運動之中。它是所有程序的源頭,我不知道它的名字,所以我將稱它為編程之道。
如果此道是完美的,那些操作系統就是完美的,如果操作系統是完美的,那么編譯程序就是完美的,如果編譯程序是完美的,那么應用程序就是完美的。用戶滿意之至--和諧便應運而生。
編程之道流逝遠去,又乘著晨風而歸。
1.2
此道產生了機器語言,機器語言又產生了匯編語言,
匯編語言產生了編譯程序,如今有了上萬種的語言。
每一種語言都有其各自的卑微用途。每一種語言都表達出軟件的陰和陽。每一種語言都在此道之中有其一席之地。
但是,應盡量避免用COBOL語言編寫程序。
1.3
宇宙之初有道,道產生了空間和時間。空間和時間便是程序設計之陰陽。
不能領悟此道的編程者總是耗盡他們所要編寫的程序的時間和空間;而領悟了此道的編程者卻總有足夠的時間和空間來達到他們的目標。
除此之外,難道還有其它的情形嗎? 1.4
精明的編程者聽說了此道,并遵循它;平庸的編程者聽說了此道,并尋覓它;愚蠢的編程者聽說了此道,卻嘲笑它。
要不是因為有嘲笑,道也就不復存在了。
最高的聲音最難被聽見。前進也是一種倒退。大器晚成。即使是一個完美的程序也仍然會有隱患。
道深藏不露,難于理解。
top
第二篇 古代的大師
編程大師如是說:
“倘若三天不編程,生活將變得毫無意義。”
2.1
老一輩的程序員是神秘的、深奧的。我們沒法揣摩他們的想法,我們所能做的只是描述一下他們的表象。
他們是清醒的,就像一只游過水面的狐貍;
他們是警惕的,就像一位戰場上的將軍;
他們是友善的,就像一位招待客人的女主人;
他們是簡單的,就像未經刻鑿的木頭;
他們還是難以琢磨的,就像黑暗的洞穴中漆黑的池水。
誰能說出他們心中的秘密?
答案只存在于道中。
2.2
計算機科學巨擘圖靈曾經夢到他是一臺機器。當他醒來時,他驚嘆道:
“我不知道--我是夢到了自己是臺機器的圖靈,還是一臺夢到了自己是圖靈的機器?”
2.3
一家大電腦公司的一名程序員參加了一次軟件研討會。他回來后向經理匯報說:“為其它公司工作的那些程序員都是些什么的人啊?他們行為拙劣,不顧及自己的儀表。他們的頭發又長又亂,衣服又皺又舊。他們闖進我們的會客組,還在我演講時發生粗魯的喧鬧。”
經理說:“我本不應該讓你去參加這個會議。那些程序員是生活在物質世界之外的。他們認為生活是荒唐的,一種意外的巧合。他們來去自如。他們只為他們的程序而活著,無憂無慮地活著。為什么要用社會習俗來約束他們呢?
他們活在此道之中。”
2.4
一個禮堂者問大師:“有位程序員,從不構思、編寫文檔或測試他的程序,然而所有知道他的人都認為他是世界上最棒的程序員。這是為什么呢?”
大 師回答說:“那個人掌握了道。他不需要事先進行構思,當系統崩潰時,他不會因此而悶悶不樂,而是心平氣和地接受整個事實。他還從編寫程序說明文檔的需要之 中超脫了出來,不在意是否有人看他的編碼。他也不需要進行測試。他的每個程序都完美無缺。寧靜而優雅,程序的用途也顯而易見。
的的確確,他已經進入了道的神奇境界。”
top
第三篇 設計
編程大師如是說:
“當程序被測試時,再修改設計方案就太遲了。”
3.1
曾經有個人去參加一次電腦展示會,每天當他進入展館時,都對門衛說:
“我是個大盜,我偷盜的本領是出了名的。事先警告你,這次展示會也在劫難逃。”
這番話讓門衛坐立不安,因為里面有價值數百萬美元的電腦設備,所以他緊緊地盯住這個人。但這個人只是從一個展攤逛到另一個展攤,嘴里輕輕地哼著小曲。
當這個人出門時,門衛把他拉到一邊,搜查他的衣服,但一無所獲。
第二天,這個人又來了,并對著門衛囂張地嚷著:“昨天我滿載而歸,但今天的收獲會更大。”于是,門衛盯他盯得更緊了,但仍一無所獲。
在展示會的最后一天,門衛再也抑制不住自己的好奇心了。“大盜先生,”門衛說,“我被你搞糊涂了,實在想不明白。請告訴我,你究竟在偷什么?”
這個人笑了。“我在偷想法。”他說。
3.2
曾經有位編程大師,喜歡編寫非結構化的編程。一位初學者試圖模仿他,也開始編寫非結構化的程序。當這位徒弟請師父評價他的進展時,師父批評了他的做法。他說:“對一位編程高手適合的,對初學者來說并不一定適合。在超越結構化之前,你必須先領悟道。”
3.3
曾經有位程序員被派到IBM的軍機大臣手下工作。軍機大臣問程序員:“設計一個財務軟件包,和設計一個操作系統,哪一個更容易?”
“操作系統。”程序員回答說。
軍機大臣立刻發生一種不信任的驚嘆,“與一個復雜的操作系統,一個財務軟件包簡直是小巫見大巫。”他說。
“并 非如此,”程序員說,“在設計一個財務軟件包時,編程人員是作為一個中介者在觀念各異的人們之間起作用的:這個軟件必須如何操作,它的報表必須是什么形 式,它必須如何與稅法一致,等等,一個操作系統則不為其外觀所限制。當設計一個操作系統時,編程人員只要在機器與人的思維之間尋找一種最簡單的和諧就可以 了。這就是為什么操作系統更容易設計。”
軍機大臣點點頭,笑了。“說來也是。但要想檢測和糾正其中的錯誤,哪個更容易呢?”
程序員沒有回答。
3.4
一位經理到編程大師那里,交給他一份有關一個新應用程序的需求說明。經理問編程大師:“如果我分配五個程序員給你,你需要多久能設計好這個系統?”
“那將花費一年的時間。”大師立刻回答。
“但我們馬上就需要這個系統,甚至要求更快!如果我分配十個程序員給你,你需要多長時間?”
大師皺了皺眉頭,“那樣的話,需要兩年。”
“如果我分配一百個程序員給你怎么樣?”
大師聳了聳肩膀,“那么這項設計將永遠無法完成。”他說
top
第四篇 編碼
編程大師如是說:
“一個寫得完美的程序是其自身的天堂,而一個寫得糟糕的程序則是其自身的地獄。”
4.1
一個程序應當是輕盈的、靈活的,它的子程序就像一串珍珠一樣連接著。它的精神和意圖應該貫穿始終。在程序中,內容既不應太多,也不應太少;既不應該有不需要的循環結構,也不該有冗余的變量;既不缺乏結構性,又不過分僵化。
一個程序,無論多么復雜,都應該以一個整體的方式運行。程序應以其內在的邏輯為指引,而非外在形態。
如果一個程序不能達到這些要求,它將處于一種雜亂無章的混淆不清的狀態。唯一的方法就是重寫這個程序。
4.2
一位初學者問大師:“我有個程序,時靈時不靈。我一直都遵循著編程的規則,結果卻整個兒搞糊涂了。這是什么原因呢?”
大師回答說:“因為你沒有領悟道,所以你迷惑不解。只有傻瓜才會指望從人類身上看到理性的行為,你又能指望一臺人類制造的機器怎么樣呢?計算機模仿的是決定論,只有道才是盡善盡美。
編程用的那些條條框框式的規則僅僅是曇花一現,只有道才是永恒的。因此,在你受到道的啟發之前,你必須沉思于道。”
“但是我怎樣才能知道我已經受到了啟發了呢?”初學者問。
“當你的程序運行無誤時。”大師回答說。
4.3
一位大師正在向他的一名初學編程的弟子解釋道的真諦。“此道體現在所有的軟件當中--不管它看上去多么無足輕重。”大師說著。
“此道體現在手掌計算器中嗎?”初學者問。
“是的。”
“此道在電子游戲中嗎?”初學者繼續問。
“此道甚至也體現在電子游戲之中。”大師說。
“那么此道也體現在個人電腦的DOS系統之中嗎?”
大師咳嗽一聲,并稍稍挪動了一下位置。“今天的課就到這里吧。”他說。
4.4
一位項目經理手下的一名程序員正編寫軟件。他的手指在鍵盤上飛舞著,在程序的編譯過程中沒有出現任何錯誤信息。程序運行起來就像一陣和風。
“太好了!”經理高興地大叫了起來,“你的技藝簡直是完美無缺。”
“技 藝?”程序員說著便從他的終端機前轉過身來,“我遵循的是道--所有的技藝遠不能及!當我剛開始編程時,我眼前看見的是整個問題亂成一團。三年之后,我再 也看不見這種一團糟的情形了。相反,我用了各種各樣的子程序。但現在,我什么也看不見了。我的整個身心存在于一種無形的虛空里,我的知覺是空蕩蕩的。
我 的精神隨其本能而動,不無原則計劃就能自由地工作。總而言之,是我的程序自己寫出了自己。誠然,有時會有一些難題。我看見那些難題向我走來,于是我放慢了 速度,默默地注視著他們。然后我更改了一行編碼,那些問題就煙消云散了。然后我完成程序的編譯。我靜靜地坐著,讓工作的歡心情舒暢遍布我的全身。我閉上雙 眼,歇息片刻,然后退出系統。”
經理說,“希望我的所有的程序員都這么聰明!”
top
第五篇 維護
編程大師如是說:
“即使一個程序只有三行長,總有一天它也不得不需要維護。”
5.1
一記扇經常開啟的門的絞鏈不需要潤滑油。
一條湍急的河流不會變得污濁。
無論是聲音還是想法都不可能在真空中傳播。
軟件如果不用就會腐朽。
這世界真奇妙。
5.2
一個程序員正在編寫他的程序,經理問他還需要多長時間完成。
“明天就可以完成。”程序員立刻回答。
“我想你這是不切實際,”經理說,“實話實說,這需要多長時間?”
程序員想了一會兒。“我還想加進一些新的特色,這需要花至少兩個星期的時間。”他最后說。
“即使那樣也期望過高,”經理堅持說,“只要你編完程序時告訴我一聲,我也就滿足了。”
程序員答應了。
幾年以后,那位經理要退休了。在他去退休午餐會的路上。他發現那個程 序員趴在他的終端機前睡著了。整個晚上都在忙于編寫那個程序。
5.3
一次一位初學編程者被指派編寫一個簡單的財務軟件包。這位初學者大張旗鼓地工作了許多天。但當他的師父檢查這套程序時,發現其中包含有一個屏幕編輯器,一套通用圖表程序,一個人工智能界面,然而卻沒有任何財務方面的東西。
當師父問及此事時,初學者顯得憤憤不平。“不要這樣沒有耐心嘛,”他說,“我最后加些財務的素材進去就是了。”
5.4
難道一位好農民會漏掉他所種的一株莊稼嗎?
難道一位好老師會放棄哪怕是最差的學生嗎?
難道一位好父親會允許哪一個孩子挨餓嗎?
難道一位好程序員會不愿維護他的程序嗎?
top
第六篇 管理
編程大師如是說:
“讓程序員多而經理少--然后生產效率就會高。”
6.1
當經理們沒完沒了地開會時,程序員就寫些游戲玩;當財務主管們談到季度利潤時,開發用的預算馬上就要被削減;當資深科學家們談論藍藍的天空時,馬上就會風起云涌。
其實,這并不是編程之道。
當經理們忠于職守時,游戲程序就會被擱置到一邊;財務主管們制訂出長 遠的計劃時,和諧秩序將很快恢復;當資深科學家們著手于眼前的問題時,這些問題不久就會解決。
其實,這才是編程之道。
6.2
為什么程序員沒有效率?
因為他們的時間浪費在開會上。
為什么程序員很難管束?
因為管理層多管閑事。
為什么程序員接二連三地辭職?
因為他們的熱情已耗盡。
在糟糕的管理之下工作,他們不再敬業。
6.3
一位經理即將被解職,但此時他手下的一名程序員發明了一個新的程序。這個程序流行起來,并且極為暢銷。結果,經理又回到了原來的崗位上。
經理試圖要發給那位程序員一筆資金,但程序員拒絕了。他說:“我寫這個程序,因為我認為這是個很有意思的想法。我并不期望有所回報。”
經理聽到這話,評論說:“這位程序員雖然身居卑位,卻能很好地理解一位雇員應盡的職責。讓我們提拔他到管理顧問的高位上吧!”
然而,接到通知后,那位程序員又一次拒絕了。他說:“我在屬于我的位置上,才能較好地編程。如果我被提升了,除了浪費每個人的時間,我將一事無成。現在我可以走了嗎?我還有一個程序要編呢。”
6.4
一位經理走過來對他的程序員們說:“關于你們的上班時間:你們要早上九點鐘到,下午五點鐘下班。”聽了這話,所有的程序員都很氣憤,其中有幾位要當場辭職。
于是,經理只好又說:“好吧,那樣的話,你們可以自己安排上班時間,只要你們能按時完成項目。”程序員們滿意了。以后,他們中午來到辦公室,一起工作到凌晨。
top
第七篇 公司里的學問
編程大師如是說:
“你可以向一位公司總裁演示一個程序,但你無法使他學會使用電腦。”
7.1
一 位初學者問大師:“在東方(此處喻指美國的東海岸,有許多大公司的總部--譯注),有一個不尋常的樹狀結構,人們稱它為‘公司總部’。它的副總裁們和財務 主管們的數量之大,使它鼓得不成開關。它簽發大師的便函,每份上都寫著”歸去”“來兮”,卻沒有人知道那是什么意思。它的那些分支機構每年都要換新的名 字,但都毫無價值。如此一個不正常的實體怎么能繼續存在呢?”
大師回答說:“你探察這個龐大的鄧因其沒有合理的用途而心神不定。難道你不能從它那無盡的回旋中得到樂趣嗎?你不會享受一下在它所蔽護的部分里的編程的那種無憂無慮的輕松嗎?你為什么要因為它毫無用處而心煩意亂呢?”
7.2
在東方,有一條大魚,比其它所有的魚都要大。它變成了一只鳥,它的翅膀就像云朵一個布滿了天空。當這只鳥飛過陸地時,它帶來了“公司總部”的消息,像蜻蜓點水一樣把這個消息丟在了那些程序員中間。然后這只鳥駕著風,背負藍天,返回了家園。
初學編程者驚奇地盯著那只鳥,因為他根本無法理解;平庸的程序員畏懼那只鳥的到來,因為他害怕鳥兒帶來的消息;而編程大師卻仍然在他的終端機前工作,因為他不知道那只鳥來了又去了。
7.3
象牙塔里的魔術師帶來了他最新的發明,要讓編程大師檢驗一下。魔術師把一只大黑箱子推進辦公室,大師靜靜地等侯著。
“這是一臺集成的、分布式的、通用的工作站,”魔術師開始,“運用人類工程學原理,使用享有專利的操作系統、第六代評議和多重狀態用戶界面而設計完成。建造這臺工作站,花了我幾百名助手幾年的時間。這不足以令人驚奇嗎?”
大師輕輕地揚了揚眉毛。“這的確令人驚奇。”他說。
“公司總部已經命令,”魔術師繼續說,“每個人都得使用這臺工作站作為操作平臺來設計新的程序。你同意嗎?”
“當然同意,”大師說,“我馬上就把它運到數據中心去。”于是魔術師興高采烈地回到了象牙塔去了。
幾天后,一位初學者走進大師的辦公室問道:“我找不到我的新程序清單了。你知道它會放在哪兒嗎?”
“知道,”大師回答說,“那些清單就堆放在數據中心的臺子(platform“可以指操作平臺”,也可以指普通的臺子--譯注)上。”
7.4
編程大師從不懼怕在設計不同程序的崗位間調來調去;管理層的變動不可能對他有所損害;他不會被解雇,即使項目取消了。這是為什么呢?因為他胸有成“道”。
top
第八篇 硬件和軟件
編程大師如是說:
“沒有風,草兒靜止不動;沒有軟件,硬件則無所為用。”
8.1
一位初學者問大師:“我覺察到有一家電腦公司比其它所有的公司都要大得多。它在中遙遙領先,就如同鶴立雞群一般。它的任意一個部門都可以組成一個完整的企業。這是為什么呢?”
大 師回答說:“你怎么問這么愚蠢的問題呢?因為那家公司大,所以它就大嘛。如果它僅僅生產硬件,沒人愿買;如果它僅僅生產軟件,沒人愿用;如果它僅僅維護一 下系統,人們將把它當作是傭人。然而,因為它把所有這些東西都結合了起來,它便搖身一變,被人們看作是諸神之一。不費吹灰之力,它便能取勝。
8.2
一天,一位大師從初學編程者身邊經過,他發現這位初學者正在全神貫注于掌上電腦游戲。“對不起,”他說,”我可以看一下嗎?”
初學者立刻緊張起來,把那個玩意兒遞給了大師。“我知道這種設備提供了三個游戲級別:容易、中等和高難,”大師說,“然而每個這樣的設備都有另一個級別,在這一級,游戲機既不想贏人,也不想被人打敗。”
“請問,尊敬的大師,”初學者懇求道,“怎樣才能找到這個奇妙的級別設置呢?”
大師把那個玩意兒扔到地上,踩到粉碎。突然間,那個初學者明白了什么。
8.3
曾 經有一個程序員,擅長在微電腦上編程,“瞧,我在這里過得多好呀,”他對另一位來訪的程序員說,這位程序員是在大型主機上工作的,“我有自己的操作系統和 文件存儲設備,我不必和其他任何人分享我的資源。這里的軟件自相一致,很容易使用。你為何不辭去現在的工作,加入到我這里來呢?”
于 是,主機程序員開始向他的這位朋友描繪他的系統:“主機就像一位陷入沉思的圣人一樣,端坐在數據中心。它的磁盤器首尾聲相連,就如同機器的海洋。這里的軟 件既像鉆石一樣能多面反射光芒,又像原始叢林一樣復雜難測。這里的程序,各具特色,它們像湍急的河流穿過系統。這就是我樂于此處的原因。
微電腦程序員聽到這里,陷入了沉默。但這兩位程序員至死都保持著友誼。
8.4
在去硅谷的路上,硬件碰上了軟件。軟件說:“你是陰,我是陽。如果我們攜手同路,我們將聞名于世,并能賺大筆的錢。”于是,這一對陰和陽便一同往前走,想著怎么征服世界。
不 一會兒,他們遇到了固件(firmware,硬件和軟件結合在一起的部件,如IC卡--譯注),他衣衫襤褸,手里拄著根帶刺的拐杖,蹣跚地走著。固件對他 們說:“道存在于陰、陽之外。它默默無聞,靜如止水。它不追求名譽,所以沒人知道它的存在;它不追求財富,因其自身完整圓滿。它存在于空間和時間之外。”
軟件和硬件,自覺慚愧,掉頭回家去了。
top
第九章 尾聲
編程大師如是說:
“現在該是你出師的時侯了。”
The Tao Of Programming
Translated by Geoffrey James
Transcribed by Duke Hillard
Transmitted by Anupam Trivedi, Sajitha Tampi, and Meghshyam Jagannath
Re-html-ized and edited by Kragen Sittler
Last modified 1996-04-10 or earlier
Table of Contents
- The Silent Void
- The Ancient Masters
- Design
- Coding
- Maintenance
- Management
- Corporate Wisdom
- Hardware and Software
- Epilogue
Book 1 - The Silent Void
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.''
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 great, then the application is great. The user is pleased and there exists harmony in the world.
The Tao of Programming flows far away and returns on the wind of morning.
1.2
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.
1.3
In the beginning was the Tao. The Tao gave birth to Space and Time. Therefore Space and Time are 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?
1.4
The wise programmer is told about Tao and follows it. The average programmer is told about Tao and searches for it. The foolish programmer is told about Tao and laughs at it.
If it were not for laughter, there would be no Tao.
The highest sounds are hardest to hear.
Going forward is a way to retreat.
Great talent shows itself late in life.
Even a perfect program still has bugs.
Book 2 - The Ancient Masters
Thus spake the master programmer:
``After three days without programming, life becomes meaningless.''
2.1
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 Tao.
2.2
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!''
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 our hospitality suite 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.''
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?''
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 Tao.''
Book 3 - Design
Thus spake the master programmer:
``When the 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 by 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 if 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 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 string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or 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 sometime 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 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 Tao is perfect.
``The rules of programming are transitory; only Tao is eternal. Therefore you must contemplate 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 Tao of 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
Prince 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 Prince exclaimed, ``Your technique is faultless!''
``Technique?'' said the programmer turning from his terminal, ``What I follow is Tao - beyond all techniques! When I first began to program I would see before me the whole problem 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 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.''
Prince Wang said, ``Would that all of my programmers were as wise!''
Book 5 - Maintenance
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 stream does not 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. ``It 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 later, the manager retired. On the way to his retirement luncheon, 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, an 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 in the financial stuff 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?
Book 6 - Management
Thus spake the master programmer:
``Let the programmers 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 thought 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. Let us 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 on."
6.4
A manager 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 at noon and work to the wee hours of the morning.
Book 7 - Corporate Wisdom
Thus spake the master programmer:
``You can demonstrate a program for a corporate executive, but you can't make him computer literate.''
7.1
A novice asked the master: ``In the east there is a great tree-structure that men call `Corporate Headquarters'. It is bloated out of shape with vice presidents and accountants. It issues a multitude of memos, each saying `Go, Hence!' or `Go, Hither!' and nobody knows what is meant. Every year new names are put onto the branches, but all to no avail. How can such an unnatural entity be?"
The master replied: ``You perceive this immense structure and are disturbed that it has no rational purpose. Can you not take amusement from its endless gyrations? Do you not enjoy the untroubled ease of programming beneath its sheltering branches? Why are you bothered by its uselessness?''
7.2
In the east there is a shark which is larger than all other fish. It changes into a bird whose wings are like clouds filling the sky. When this bird moves across the land, it brings a message from Corporate Headquarters. This message it drops into the midst of the programmers, like a seagull making its mark upon the beach. Then the bird mounts on the wind and, with the blue sky at its back, returns home.
The novice programmer stares in wonder at the bird, for he understands it not. The average programmer dreads the coming of the bird, for he fears its message. The master programmer continues to work at his terminal, for he does not know that the bird has come and gone.
7.3
The Magician of the Ivory Tower brought his latest invention for the master programmer to examine. The magician wheeled a large black box into the master's office while the master waited in silence.
``This is an integrated, distributed, general-purpose workstation,'' began the magician, ``ergonomically designed with a proprietary operating system, sixth generation languages, and multiple state of the art user interfaces. It took my assistants several hundred man years to construct. Is it not amazing?''
The master raised his eyebrows slightly. ``It is indeed amazing,'' he said.
``Corporate Headquarters has commanded,'' continued the magician, ``that everyone use this workstation as a platform for new programs. Do you agree to this?''
``Certainly,'' replied the master, ``I will have it transported to the data center immediately!'' And the magician returned to his tower, well pleased.
Several days later, a novice wandered into the office of the master programmer and said, ``I cannot find the listing for my new program. Do you know where it might be?''
``Yes,'' replied the master, ``the listings are stacked on the platform in the data center.''
7.4
The master programmer moves from program to program without fear. No change in management can harm him. He will not be fired, even if the project is cancelled. Why is this? He is filled with Tao.
Book 8 - Hardware and Software
Thus spake the master programmer:
``Without the wind, the grass does not move. Without software, hardware is useless.''
8.1
A novice asked the master: ``I perceive that one computer company is much larger than all others. It towers above its competition like a giant among dwarfs. Any one of its divisions could comprise an entire business. Why is this so?''
The master replied, ``Why do you ask such foolish questions? That company is large because it is large. If it only made hardware, nobody would buy it. If it only made software, nobody would use it. If it only maintained systems, people would treat it like a servant. But because it combines all of these things, people think it one of the gods! By not seeking to strive, it conquers without effort.''
8.2
A master programmer passed a novice programmer one day. The master noted the novice's preoccupation with a hand-held computer game. ``Excuse me,'' he said, ``may I examine it?''
The novice bolted to attention and handed the device to the master. ``I see that the device claims to have three levels of play: Easy, Medium, and Hard,'' said the master. ``Yet every such device has another level of play, where the device seeks not to conquer the human, nor to be conquered by the human.''
``Pray, great master,'' implored the novice, ``how does one find this mysterious setting?''
The master dropped the device to the ground and crushed it underfoot. And suddenly the novice was enlightened.
8.3
There was once a programmer who worked upon microprocessors. ``Look at how well off I am here,'' he said to a mainframe programmer who came to visit, ``I have my own operating system and file storage device. I do not have to share my resources with anyone. The software is self- consistent and easy-to-use. Why do you not quit your present job and join me here?''
The mainframe programmer then began to describe his system to his friend, saying ``The mainframe sits like an ancient sage meditating in the midst of the data center. Its disk drives lie end-to-end like a great ocean of machinery. The software is as multifaceted as a diamond, and as convoluted as a primeval jungle. The programs, each unique, move through the system like a swift-flowing river. That is why I am happy where I am.''
The microcomputer programmer, upon hearing this, fell silent. But the two programmers remained friends until the end of their days.
8.4
Hardware met Software on the road to Changtse. Software said: ``You are Yin and I am Yang. If we travel together we will become famous and earn vast sums of money.'' And so the set forth together, thinking to conquer the world.
Presently they met Firmware, who was dressed in tattered rags and hobbled along propped on a thorny stick. Firmware said to them: ``The Tao lies beyond Yin and Yang. It is silent and still as a pool of water. It does not seek fame, therefore nobody knows its presence. It does not seek fortune, for it is complete within itself. It exists beyond space and time.''
Software and Hardware, ashamed, returned to their homes.
Book 9 - Epilogue
Thus spake the master programmer:
``It is time for you to leave.''