文学编程

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

概念

文学程序是用自然语言（比如英语）写出来的对程序逻辑的解释，程序中交织点缀着宏和传统源代码段。在文学编程的源文件中，宏很简单，它或与标题类似，或是解决编程问题时用人类语言描述抽象的解释性短语。它把代码段或更低层次的宏隐藏了起来，且与计算机科学教学时经常用到的，用伪代码写的算法相似。这些任意解释的短语成为新的精确的操作符，操作符由程序员在运行过程中创建，组成了在基本编程语言之上的“元语言”。
预处理器用于替换任意层级，说得更准确些是“在'网'和宏之间创建联系”，用命令"tangle"产生可编译源代码，用命令"weave"产生文档。预处理器还提供了写出宏的内容的能力和在文学程序源文件中的任何地方增加已创建的宏的能力，由此不必受传统编程语言强加的那些限制或是打断自己的思路。

优点

根据高德纳本人所说,文学编程为高质量程序而生，因为它强迫程序员显式描述程序背后的思路，让不充分的设计决策无所遁形。高德纳还声称文学编程提供了一流的文档系统，它并非插件，而是随着编程思路的慢慢展现而不断自然发展的过程。产生出来的文档使作者能在以后的任何时间重新找到自己的思路，也能使其他程序员更容易理解程序的建构过程。这与传统文档不同，那里程序员必须和编译器规定的代码顺序写在一起，还必须从代码和注释中重现当时的思路。文学编程的元语言能力也据称普遍利于思考，能从更高的层次统观代码，也能增加人的智能可成功保持和处理的概念数量。Applicability of the concept to programming on a large scale, that of commercial-grade programs is proven by an edition of TeX code as a literate program.

误解

文学编程常常被误解为不过是从有源代码和注释的文件中产生格式化文档，或是在代码里写大量的注释。这一误解导致那些文档析出工具，如Perl的Plain Old Documentation系统也被称为“文学编程工具”。尽管如此，因为这些工具没有实现隐藏在自然语言宏系统背后的“抽象概念网”，或是提供把机器规定的源代码顺序变为人类思维更容易理解的顺序的能力，它们不能在高德纳提出的意义下被称作文学编程工具。

文学编程工具

第一个发布的文学编程环境是WEB，由高德纳于1981年为他的TeX排版系统而引入。它使用Pascal作为其基础编程语言，使用TeX作为文档排版工具。The complete commented TeX source code was published in Knuth's TeX: The program, volume B of his 5-volume Computers and Typesetting. Knuth had privately used a literate programming system called DOC as early as 1979. He was inspired by the ideas of Pierre-Arnoul de Marneffe. The free CWEB, written by Knuth and Silvio Levy, is WEB adapted for C and  C++, runs on most operating systems and can produce TeX and PDF documentation. 
其它的文学编程概念的实现有noweb和FunnelWeb，它们都是源代码独立的。Noweb以其简单而知名：just 2 text markup conventions and 2 tool invocations are needed to use it, and it allows for text formatting in HTML rather than going through the TeX system. FunnelWeb is another program without dependency on TeX which can produce HTML documentation output. It has more complicated markup (with "@" escaping any FunnelWeb command), but has many more flexible options. 
The Leo text editor is an outlining editor which supports optional noweb and CWEB markup. The author of Leo actually mixes two different approaches: first, Leo is an outlining editor, which helps with management of large texts, second, Leo incorporates some of the ideas of literate programming, which in its pure form (i.e. the way it is used by Knuth Web tool and/or tools like "noweb") is possible only with some degree of inventiveness and the use of the editor in a way not exactly envisioned by its author (in modified @root nodes). However this and other extensions (@file nodes) make outline programming and text management successful and easy and in some ways similar to literate programming.
Haskell编程语言对半文学编程有原生支持，其来源于CWEB但用了较简单的实现。如果想要TeX输出，你可以写a plain LaTeX file where source code is marked by a given surrounding environment; LaTeX can be set up to handle that environment, while the Haskell compiler looks for the right markers to identify Haskell statements to compile, removing the TeX documentation as if they were comments. However, as described above, this is not literate programming in the sense intended by Knuth. Haskell's functional, modular nature makes literate programming directly in the language somewhat easier, but it is not nearly as powerful as one of the a WEB tools where "tangle" can reorganize in arbitrary ways.