当前位置: 首页 > 工具软件 > Literate > 使用案例 >

文艺编程 Literate Programming (原文中英文对照)

韩淇
2023-12-01

转载自:http://legendsland.wordpress.com/2012/06/06/literate-programming-%E6%96%87%E8%89%BA%E7%BC%96%E7%A8%8B/

译注:这篇文章是 Donald Knuth 一篇1983年的论文:Literate Programming 的介绍部分。有人翻译为“字面编程”,是极其错误的说法,literate 根本就没有“字面”这个意思,字面的英文单词是 literal, literate 意指能读能写,Donald Knuth 同时也认为编程是一门艺术,因此将其译为“文艺编程”,甚为妥当。论文发表近30年,未见谁真正用好了LP。译此文,希望能更正至今都错误的中文译法。保守估计,10年内 LP 仍然不会流行起来,因为没有谁既是伟大的作家,又是伟大的程序员 —— 除了 Donald Knuth)

The past ten years have witnessed substantial improvements  in programming methodology. This advance, carried out under the banner of  “structured programming,” has led to programs that are more reliable and  easier to comprehend; yet the results are not entirely satisfactory. My  purpose in the present paper is to propose another motto that may be  appropriate for the next decade, as we attempt to make further progress in  the state of the art. I believe that the time is ripe for significantly  better documentation of programs, and that we can best achieve this by  considering programs to be works of literature. Hence, my title: “Literate  Programming.”

过去十年见证了编程方法学上重要的进步。这个进步是在“结构化编程”的大旗下发展起来的,尽管结果并非完美,但它让程序变得更可靠也更易读。当我们努力推进编程技术进一步发展时,本论文的目的就是提出下一个十年口号。我相信,在文档化程序方面,更好更重要的时机已经成熟。为达此目标,最好的方法是将程序当作文学作品。故此,标题为:“文艺编程”。

 

Let us change our traditional attitude to the construction  of programs: Instead of imagining that our main task is to instruct a  computer what to do, let us concentrate rather on explaining to human beings  what we want a computer to do.

让我们改改传统上构建程序的态度:不要认为程序的主要任务是指导计算机怎么做,相反,程序要致力于向人们解释,它想让计算机做什么。

 

The practitioner of literate programming can be regarded  as an essayist, whose main concern is with exposition and excellence of  style. Such an author, with thesaurus in hand, chooses the names of variables  carefully and explains what each variable means. He or she strives for a  program that is comprehensible because its concepts have been introduced in  an order that is best for human understanding, using a mixture of formal and  informal methods that reinforce each other.

文艺编程人士可被视为作家,他们首要考虑的任务是如何清楚地阐述、如何形成优秀的风格。这样的作者胸有成竹,会仔细地挑选变量名,并给予解释。为力求程序之可读,他/她使用形式和非形式互补的混合手法,将各种概念按照人们能理解的方式顺序编排下来。

 

I dare to suggest that such advances in documentation are  possible because of the experiences I’ve had during the past several years  while working intensively on software development. By making use of several  ideas that have existed for a long time, and by applying them systematically  in a slightly new way, I’ve stumbled across a method of composing programs  that excites me very much. In fact, my enthusiasm is so great that I must  warn the reader to discount much of what I shall say as the ravings of a fanatic  who thinks he has just seen a great light.

之所以胆敢对文档化提出这样的要求,那是因为我过去多年的高强度软件开发经验。依靠人们长久以来形成的诸多想法,我系统而又略带新意地应用它们,最终摸索出一套让我兴奋不已的创作程序的方法。事实上,我太热情太痴迷于此,我要警告读者朋友们,对我那些窥见圣光之类的狂言乱语,你们要适听而止。

 

Programming is a very personal activity, so I can’t be  certain that what has worked for me will work for everybody. Yet the impact  of this new approach on my own style has been profound, and my excitement has  continued unabated for more than two years. I enjoy the new methodology so  much that it is hard for me to refrain from going back to every program that  I’ve ever written and recasting it in “literate” form. I find myself unable  to resist working on programming tasks that I would ordinarily have assigned  to student research assistants; and why? Because it seems to me that at last  I’m able to write programs as they should be written. My programs are not  only explained better than ever before; they also are better programs,  because the new methodology encourages me to do a better job. For these  reasons I am compelled to write this paper, in hopes that my experiences will  prove to be relevant to others.

新方法对我自己风格的影响极其深远,而且这种兴奋感持续两年多,未曾减退。但编程是非常个人化的行为,对我适合的,我并不确定是否适合所有人。我强烈地爱上了这套新方法,对过去写的每一个程序,我都抑制不住地想将它们“文艺”化。我发现自己忍不住去编那些布置给学生助教们的作业程序,为何?因为对我而言,我最终能写出那些程序,而那正是本该被写成的样子。新方法促使我写出比以往更可读、也更好的程序。基于上述原因,特拟此文,希望其他人能分享到我的经验。

 

I must confess that there may also be a bit of malice in  my choice of a title. During the 1970s I was coerced like everybody else into  adopting the ideas of structured programming, because I couldn’t bear to be  found guilty of writing unstructured programs. Now I have a chance to get  even. By coining the phrase “literate programming,” I am imposing a moral  commitment on everyone who hears the term; surely nobody wants to admit  writing an illiterate program.

必须承认,标题有点恶搞。在70年代,若被发现用了非结构化编程,我会心生惭愧而难堪忍受,于是像所有人一样,被迫接受了结构化编程的思想。现有有机会扳平了。我构造出“文艺编程”这个说法,于是每个听到此说法的人,会被迫作出道德上的承诺。毕竟,绝没有人会承认自己在编写文盲 (illiterate) 程序。

 


 类似资料: