encyclopegia.org

Literate programming

is the seminal book on literate programming. Literate programming (LP) is a programming paradigm introduced in 1984 by Donald Knuth in which a computer program is given as an explanation of how it works in a natural language, such as English, interspersed (embedded) with snippets of macros and traditional source code, from which compilable source code can be generated. The approach is used in scientific computing and in data science routinely for reproducible research and open access purposes. Literate programming tools are used by millions of programmers today. The literate programming paradigm, as conceived by Donald Knuth, represents a move away from writing computer programs in the manner and order imposed by the compiler, and instead gives programmers macros to develop programs in the order demanded by the logic and flow of their thoughts. Literate programs are written as an exposition of logic in more natural language in which macros are used to hide abstractions and traditional source code, more like the text of an essay. Literate programming tools are used to obtain two representations from a source file: one understandable by a compiler or interpreter, the "tangled" code, and another for viewing as formatted documentation, which is said to be "woven" from the literate source.…

is the seminal book on literate programming. Literate programming (LP) is a programming paradigm introduced in 1984 by Donald Knuth in which a computer program is given as an explanation of how it works in a natural language, such as English, interspersed (embedded) with snippets of macros and traditional source code, from which compilable source code can be generated. The approach is used in scientific computing and in data science routinely for reproducible research and open access purposes. Literate programming tools are used by millions of programmers today. The literate programming paradigm, as conceived by Donald Knuth, represents a move away from writing computer programs in the manner and order imposed by the compiler, and instead gives programmers macros to develop programs in the order demanded by the logic and flow of their thoughts. Literate programs are written as an exposition of logic in more natural language in which macros are used to hide abstractions and traditional source code, more like the text of an essay. Literate programming tools are used to obtain two representations from a source file: one understandable by a compiler or interpreter, the "tangled" code, and another for viewing as formatted documentation, which is said to be "woven" from the literate source. While the first generation of literate programming tools were computer language-specific, the later ones are language-agnostic and exist beyond the individual programming languages. The following snippet of the wc literate program shows how arbitrary descriptive phrases in a natural language are used in a literate program to create macros, which act as new "operators" in the literate programming language, and hide chunks of code or other macros. The mark-up notation consists of double angle brackets ( <<...>> ) that indicate macros. The @ symbol which, in a noweb file, indicates the beginning of a documentation chunk. The <<*>> symbol stands for the "root", topmost node the literate programming tool will start expanding the web of macros from. Actually, writing out the expanded source code can be done from any section or subsection (i.e. a piece of code designated as <<name of the chunk>>= , with the equal sign), so one literate program file can contain several files with machine source code. The purpose of wc is to count lines, words, and/or characters in a list of files. The number of lines in a file is ......../more explanations/ Here, then, is an overview of the file wc.c that is defined by the noweb program wc.nw: >= > > > > > @ We must include the standard I/O definitions, since we want to send formatted output to stdout and stderr. >= #include @ The unraveling of the chunks can be done in any place in the literate program text file, not necessarily in the order they are sequenced in the enclosing chunk, but as is demanded by the logic reflected in the explanatory text that envelops the whole program. The present chunk, which does the counting, was actually one of the simplest to write. We look at each character and change state if it begins or ends a word. >= while (1) { > c = *ptr++; if (c > ' ' && c The macros stand for any chunk of code or other macros, and are more general than top-down or bottom-up "chunking", or than subsectioning. Donald Knuth said that when he realized this, he began to think of a program as a web of various parts. In a noweb literate program besides the free order of their exposition, the chunks behind macros, once introduced with <<...>>= , can be grown later in any place in the file by simply writing <<name of the chunk>>= and adding more content to it, as the following snippet illustrates ( + is added by the document formatter for readability, and is not in the code). ==See also== Documentation generator – the inverse on literate programming where documentation is embedded in and generated from source code Notebook interface – virtual notebook environment used for literate programming Sweave and Knitr – examples of use of the "noweb"-like Literate Programming tool inside the R language for creation of dynamic statistical reports Self-documenting code – source code that can be easily understood without documentation Vibe coding

References

No reference rows published for this article.

Cite this article

MLA

"Literate programming." encyclopegia.org, 2026, https://encyclopegia.org/wiki/literate-programming. Accessed 24 November 2026.

Chicago

"Literate programming." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/literate-programming.

APA

encyclopegia.org. (2026). Literate programming. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/literate-programming

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Category:Programming languages

stub · references available

programming paradigm

stub · references available

extreme programming

stub · references available

high-level programming language

stub · references available

logic programming

stub · references available

return-oriented programming

stub · references available

in-system programming

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1374374269 · 0.5 · snapshot enwiki-001374374269

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.