Coding
Book Four
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?"
“也存在于个人计算机的DOS里吗?”
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!"
“什么时候我的程序员才能都达到这样的境界!”
Mainteance
Book Five
Thus spake the master programmer:
编程大师如是说:
"Though a program be but three lines long, someday it will have to be maintained."
“既使一个程序只有三行长,也总有一天需要去维护它”
原文地址 linux/docs/linux-3274.htm#book1" target=_blank>http://www.lslnet.com/linux/docs/linux-3274.htm#book1
分享到:
相关推荐
《卓越编程之道 - 卷2》是一本深受程序员喜爱的编程指南,主要聚焦于底层编程思维和高级语言的编写。作者Randall Hyde以其独特的视角和深入浅出的讲解,为读者揭示了编程世界的奥秘。这本书是《Write Great Code》...
编程之道,编程之道-pdf
总之,《编程之道-IOS设计模式解析》是一本全面且实用的iOS设计模式指南,它不仅能提升开发者对设计模式的理解,也能帮助他们更好地应对iOS开发中的各种挑战。通过深入学习和实践,开发者可以提升自己的编程技巧,...
Rust编程之道-随书编程.zip,看清楚哦,是随书编程的内容
Objective-C编程之道主要聚焦于如何在iOS开发中运用设计模式,设计模式是软件工程中的一种最佳实践,通过解决常见问题来提升...因此,这份"Objective-C编程之道-设计模式源码"是一个宝贵的参考资料,值得深入研究。
4. **时间与空间**:“编程之道”认为时间和空间是编程的基本要素,不懂得利用好时间和空间的程序员往往会遇到瓶颈。而真正理解“编程之道”的程序员则能高效地管理时间和空间,从而实现目标。 #### 三、程序员的...
《编程之道-C#篇》是一本深入探讨C#编程语言的书籍,旨在帮助读者掌握C#的核心概念和技术,提升编程技能。习题答案的提供,为读者提供了自我检验和学习巩固的机会,使得理论与实践相结合,更好地理解并应用所学知识...
【标题】"分享洪恩编程之道所有源码-vb.net" 涉及的知识点主要集中在VB.NET编程语言以及编程实践上。洪恩编程之道是一本面向初学者和进阶者的编程教材,它通过一系列的案例来教授VB.NET的基础知识和编程技巧。以下...
要学习编程是要有很大恒心和毅力的,首先你要明确自己的目标,想好自己编程是为了干什么。如果你学习仅仅只是一时想编出QUAKE和成为比尔盖次的冲动,那么我劝你还是应该不要开始学习,因为这样的目标很难支持你日后...
《编程之道-C#篇》是一本深入探讨C#编程语言的资源集合,包含了丰富的源代码示例。这个压缩包文件提供了学习和理解C#编程语言的宝贵材料,适合初学者和有一定经验的开发者。让我们一起来深入挖掘其中所涵盖的知识点...
《编程之道》是一本深入探讨编程艺术和技术的书籍,它涵盖了编程实践的各个方面,旨在帮助读者提升编程技能,理解编程的本质,并掌握编程之道。书名中的“道”寓意着编程不仅仅是技术的堆砌,更是思想的体现和智慧的...
S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程安装包SP9S7-200编程...
《编程之道》是一本深入探讨计算机编程艺术与实践的书籍,其核心理念在于教导读者如何以更为高效、优雅的方式编写代码。"编程之道"这一标签,暗示了书中的内容不仅涵盖了基础的编程语法和概念,更注重编程思维的培养...
编程之道ASP数据库编程入门
《安全编程之道》是一本专注于C和C++编程语言的安全编程指南,旨在帮助开发者提升代码质量和安全性,防止软件漏洞导致的潜在威胁。本书基于“program secure”理念,深入探讨了如何在开发过程中实施最佳安全实践。 ...
《VC++编程之道》是一本深入探讨Visual C++编程技术的专业书籍,其配书光盘包含了大量的源代码示例,旨在帮助读者更好地理解和实践书中所讲解的编程概念和技术。光盘中的"MR"可能代表“Master Resource”,暗示了这...
最全最新版 Objective-C编程之道IOS设计模式解析.pdf
这篇博客“对话框高级编程——公共控件之一(旋转按钮、滑块和进度条)”主要探讨了三种常用的公共控件:旋转按钮(Spin Button)、滑块(Slider)和进度条(Progress Bar),并提供了源码示例。这些控件在很多应用...