冷面阎罗

低调做人&&高调做事
随笔 - 208, 文章 - 3, 评论 - 593, 引用 - 0
数据加载中……

转载:编 程 之 道 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

  1. The Silent Void
  2. The Ancient Masters
  3. Design
  4. Coding
  5. Maintenance
  6. Management
  7. Corporate Wisdom
  8. Hardware and Software
  9. 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.''

posted on 2006-12-11 21:19 冷面阎罗 阅读(1663) 评论(2)  编辑  收藏

评论

# re: 转载:编 程 之 道 The Tao Of Programming  回复  更多评论   

very interesting
2006-12-12 10:02 | Fisher

# re: 转载:编 程 之 道 The Tao Of Programming  回复  更多评论   

啊,不错啊!!!
2006-12-17 21:10 | 金天

只有注册用户登录后才能发表评论。


网站导航: