Literate programming

from Wikipedia, the free encyclopedia

With literate programming (English, approximately translatable with literary programming ) one describes the writing of computer programs in a form so that they can be read primarily by humans.

From a technical point of view, literate programming means that both the documentation and the source code of the program are available in a common file . Special tools ensure that both the source text and the documentation can be extracted from this file. Since the focus is on documentation written for humans, the order of the program expressions is designed so that they can be documented in an understandable manner.

motivation

In Communications of the ACM 1986 Jon Bentley asks: When was the last time you spent a pleasant evening in a comfortable chair, reading a good program? (German: "When was the last time that you spent a pleasant evening in a comfortable armchair and read a good program?") The background to this question is based on the fact that some programmers do excellent work and accordingly creates good programs, but hardly any programmer documents his programs sufficiently.

history

The problem addressed was recognized earlier: The first programming environment that supported literate programming was WEB developed by Donald Knuth . Developed in 1981 for the implementation of the TeX system, it used Pascal as the programming language and TeX as the documentation generator. WEB's successor was CWEB , which used C as a basis.

Characteristics of a literate programming system

A literate programming system enables the following:

  1. Source code and comments can be mixed together.
  2. The source code sections can be arranged in any order. The literate programming system automatically puts them together in sequence so that they can be executed ( tangle ).
  3. Readable documentation with table of contents, references, registers, etc. can be created automatically from the program and description ( weave ).

Related concepts and programs

The original concept was finally adopted by other developers and was also partially reflected in other programming languages.

Documentation Generators

The documentation generator Doxygen (similar to Java with Javadoc ) partially implements the concept: Specially formatted comments in the source text (in one of the supported programming languages) can be extracted and included in documentation. In contrast to the original idea, this concept only enables a detailed specification of the source text and its structure ( function parameters can be precisely specified). A complete documentation of the source text, however, is not possible with these programs, also precisely because it is not possible to rearrange the program.

Special programming languages

The Haskell programming language already allows literate programming at source code level: Comments and program instructions can be mixed as desired. In contrast to other programming languages, with this strategy the source text is specially marked - and not the associated comments. A rearrangement is not possible here either.

General typesetting systems

By suitably interlacing the source code and commentary, one can achieve literate programming when using suitable typesetting systems . For example, you can write C source code in such a way that it can be compiled into a program with the C compiler, but with troff / groff a Postscript document with graphics can also be generated from it. Compared to "real" literate programming tools, some restrictions in functionality have to be accepted, since special software can offer more options than general typesetting systems.

Programming by intention

Programming by intention (not to be confused with intentional programming ) is a concept of agile software development which states that when implementing methods, algorithms are not implemented as usual, but “only” intentions are written down. These intentions then usually correspond to further auxiliary methods or single-line algorithms. This ensures that the program is extremely easy to read, even without programming knowledge.

software

  • WEB (the original)
  • Noweb
  • CWEB by Marc van Leeuwen
  • funnelweb (not based on WEB / CWEB)
  • fweb (further development of CWEB)
  • LEO , "Literate Editor with Outlines"

literature

  • Donald E. Knuth: Literate Programming . In: The Computer Journal . tape 27 , no. 2 , 1984, p. 97–111 , doi : 10.1093 / comjnl / 27.2.97 ( online PDF).
  • Stefan Mintert: Not without a name. Literate programming with XSLT . In: iX . No. 4 , 2005, p. 135-137 .
  • Stefan Lindner: literary programming . Donald E. Knuth's WEB system. In: c't . No. 10 , 1990, pp. 340 .

Web links

Individual evidence

  1. The source code of TeX was published in TeX: The program by Donald Knuth
  2. Example of the use of troff / groff for literate programming
  3. Programming by Intention, Essential Skills for the Agile Developer (PDF; 731 kB)