Literate programming
From Wikipedia, the free encyclopedia
Literate programming is a philosophy of computer programming based on the premise that a computer program should be written similar to literature, with human readability as a primary goal. According to this philosophy, programmers should aim for a “literate” style in their programming just as writers aim for an intelligible and articulate style in their writing. This philosophy contrasts with the mainstream view that the programmer’s primary or sole objective is to create source code and that documentation should only be a secondary objective.
In practice, literate programming is achieved by combining human-readable documentation and machine-readable source code into a single source file, in order to maintain close correspondence between documentation and source code. The order and structure of this source file are specifically designed to aid human comprehension: code and documentation together are organized in logical and/or hierarchical order (typically according to a scheme that accommodates detailed explanations and commentary as necessary). At the same time, the structure and format of the source files accommodate external utilities that generate program documentation and/or extract the machine-readable code from the same source file(s) (e. g., for subsequent processing by compilers or interpreters).
Contents |
[edit] History and current implementations
The first published literate programming environment was WEB, introduced by Donald Knuth in 1981 for his TeX typesetting system; it uses Pascal as its underlying programming language and TeX for typesetting of the documentation.
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[1] 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. Other implementations of the concept are noweb and FunnelWeb, both of which are independent of the programming language of the source code.
The Leo (text editor) supports optional noweb and CWEB markup[2].
The Haskell programming language has native support for literate programming, inspired by CWEB but with a simpler implementation. When aiming for TeX output, one writes 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.
[edit] See also
[edit] Bibliography
- Donald E. Knuth, Literate Programming, Stanford, California: Center for the Study of Language and Information, 1992, CSLI Lecture Notes, no. 27.
- Eitan M. Guari, TeX & LaTeX Drawing and Literate Programming. McGraw Hill 1994. ISBN 0-07-911616-7 (includes software).
[edit] References
- ^ Pierre Arnoul de Marneffe, Holon Programming. Univ. de Liege, Service d'Informatique (December, 1973).
- ^ Leo (text editor) homepage cites support for noweb and CWEB
[edit] External links
- comp.programming.literate FAQ at internet FAQ archives
- Literate Programming newsgroup
- Literate Programming website
- LiteratePrograms is a literate programming wiki.
- Select: A literate programming example using noweb
- Softpanorama page on literate programming
- Haskell literate programming, Specification of literate programming in the Haskell Report, the accepted Haskell standard