文艺编程 Literate Programming

时间:2022-09-13 17:57:07

译注:这篇文章是 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) 程序。

wikipedia关于文艺编程的解释:

文学编程英语:Literate programming)是由高德纳提出的编程方法,希望能用来取代结构化编程范型。[1]

正如高德纳所构想的那样,文学编程范型不同于传统的由计算机强加的编写程序的方式和顺序,而代之以让程序员用他们自己思维内在的逻辑和流程所要求的顺序开发程序。[2]文学编程*地表达逻辑,而且它用人类日常使用的语言写出来,就好像一篇文章一样,文章里包括用来隐藏抽象的和传统的源代码。文学编程工具用来从文学源文件中获得两种表达方式,一种用于计算机进一步的编译和执行,称作“绕出”(tangled)的代码,一种用于格式化文档,称作从文学源代码中“织出”(woven)。[3]。虽然第一代文学编程工具特定于计算机语言,但后来的工具可以不依赖具体语言,并且存在于比编程语言更高的层次中。

http://zh.wikipedia.org/wiki/%E6%96%87%E5%AD%A6%E7%BC%96%E7%A8%8B

文艺编程 Literate Programming的更多相关文章

  1. .Net中的反应式编程(Reactive Programming)

    系列主题:基于消息的软件架构模型演变 一.反应式编程(Reactive Programming) 1.什么是反应式编程:反应式编程(Reactive programming)简称Rx,他是一个使用LI ...

  2. Unity基于响应式编程(Reactive programming)入门

    系列目录 [Unity3D基础]让物体动起来①--基于UGUI的鼠标点击移动 [Unity3D基础]让物体动起来②--UGUI鼠标点击逐帧移动 时光煮雨 Unity3D让物体动起来③—UGUI DoT ...

  3. 2018-02-27 "Literate Programming"一书摘记之一

    书到后才发现是Knuth的论文集, 第一篇就在网上: Computer programming as an art (1974). 其中"Taste and Style"(品味和风 ...

  4. 算法编程Algos Programming

    算法编程Algos Programming 不同算法的集合,用于编程比赛,如ACM ICPC. 算法按主题划分.大多数算法都可以从文件中按原样运行.每种算法都有一个参考问题,并对其时间和空间复杂度作了 ...

  5. Java 中的函数式编程(Functional Programming):Lambda 初识

    Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...

  6. 关于函数式编程(Functional Programming)

    初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...

  7. 学习笔记之编程珠玑 Programming Pearls

    Programming Pearls (2nd Edition): Jon Bentley: 0785342657883: Amazon.com: Books https://www.amazon.c ...

  8. iOS运行时编程(Runtime Programming)和Java的反射机制对比

    运行时进行编程,类似Java的反射.运行时编程和Java反射的对比如下:   1.相同点   都可以实现的功能:获取类信息.属性设置获取.类的动态加载(NSClassFromString(@“clas ...

  9. 面向函数范式编程(Functional programming)

    函数编程(简称FP)不只代指Haskell Scala等之类的语言,还表示一种编程思维,软件思考方式,也称面向函数编程. 编程的本质是组合,组合的本质是范畴Category,而范畴是函数的组合. 首先 ...

随机推荐

  1. 第六步:Lucene查询索引(优化一)

    package cn.harmel.lucene; import java.io.IOException; import java.nio.file.Paths; import org.apache. ...

  2. SSI指令使用详解(转)

    什么是 SHTML使用SSI(Server Side Include)的html文件扩展名,SSI(Server Side Include),通常称为“服务器端嵌入”或者叫“服务器端包含”,是一种类似 ...

  3. Git push 提交代码到远程global user.name错误解决办法

    问题:安装了Git-1.9.4-preview和TortoiseGit等工具后,Git服务器开通了账号和密码并配置了邮箱.克隆了服务器代码到本地,按需求进行代码开发.提交本地代码到服务器时出现错误.具 ...

  4. 【题解】JSOIWC2019 Round 5

    题面: 题解: T1: 算法1: 枚举每个灯塔的方向,并分别判断是否有解.时间复杂度O(K*4^K). 预计得分:50-70分 算法2: 不难发现,当k≥4的时候一定有解,将最靠左的两个下面的朝右上. ...

  5. CodeForces701E DFS

    http://codeforces.com/problemset/problem/701/E 一个显而易见的方法是考虑点的贡献,一次dfs记录到所有根节点不考虑匹配的答案,再一次dfs反向推出答案 # ...

  6. 创建文件夹c++

    linux #include <sys/types.h> #include <sys/stat.h> string filepath; mkdir(filepath.c_str ...

  7. bzoj2733&colon; &lbrack;HNOI2012&rsqb;永无乡 启发式合并

    地址:http://www.lydsy.com/JudgeOnline/problem.php?id=2733 题目: 2733: [HNOI2012]永无乡 Time Limit: 10 Sec   ...

  8. 大数据入门第十一天——hive详解(二)基本操作与分区分桶

    一.基本操作 1.DDL 官网的DDL语法教程:点击查看 建表语句 CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name [(col_name data ...

  9. rocketmq持久化方式

    推荐看下RocketMQ,使用文件做持久化, 并支持分布式事务(虽然可能造成较多的写脏), 异步刷盘,内存预分配, 高可用采用了同步双写及异步复制的方式, 通信是用netty做的,基本上所有耗时的操作 ...

  10. 并查集——hdu1232(入门)

    传送门:畅通工程 实质是求连通分支的数量 #include <iostream> #include <cstdio> #include <algorithm> us ...