Literate Programming

by Donald E. Knuth (Stanford, California: Center for the Study of Language and Information, 1992), xvi+368pp.
(CSLI Lecture Notes, no. 27.)
ISBN 0-937073-80-6
Japanese translation by Makoto Arisawa, Bungeiteki Programming (Tokyo: ASCII Corporation, 1994), 463pp.

This book is the first in a series of eight volumes that contain archival forms of my published papers, together with new material.

Literate programming is a methodology that combines a programming language with a documentation language, thereby making programs more robust, more portable, more easily maintained, and arguably more fun to write than programs that are written only in a high-level language. The main idea is to treat a program as a piece of literature, addressed to human beings rather than to a computer. The program is also viewed as a hypertext document, rather like the World Wide Web. (Indeed, I used the word WEB for this purpose long before CERN grabbed it!) This book is an anthology of essays including my early papers on related topics such as structured programming, as well as the article in The Computer Journal that launched Literate Programming itself. The articles have been revised, extended, and brought up to date.

Table of Contents:

  1. Computer programming as an art [P68]
  2. Structured programming with go to statements [P67]
  3. A structured program to generate all topological sorting arrangements [P65]
  4. Literate programming [P109]
  5. Programming pearls: Sampling [Q78]
  6. Programming pearls, continued: Common words [Q79]
  7. How to read a WEB [from TeX: The Program]
  8. Excerpts from the programs for TeX and METAFONT [from Computers & Typesetting, volumes B and D]
  9. Mathematical writing [from Mathematical Writing]
  10. The errors of TeX [P124]
  11. The error log of TeX [P124, with new material]
  12. An example of CWEB [never before published]
  13. Further reading: A comprehensive bibliography of Literate Programming [never before published]

(Numbers like P68 and Q78 in this list refer to the corresponding papers in my list of publications.)

Available from the publisher (CSLI), and also from the distributor (University of Chicago Press).

This book received the Productivity Award from Computer Language magazine, 1992, awarded to products that significantly increase programmer productivity.

Quick introduction to literate programming by Chris Lee

Matt Pharr plugs Literate Programming when receiving his 2013 Oscar with Greg Humphreys and Pat Hanrahan!

Errata

For a list of corrections to errors in the first printing of this book, you may download either the errata file in plain TeX format (8812 bytes) or the errata file in DVI format (10816 bytes) or the errata file in compressed PostScript format (34478 bytes); the latter files were generated by the TeX file, and last updated 12 Jun 2004. Most of the errors in the first two printings were corrected in the third printing, but several minor and not-so-minor errors have been found by sharp-eyed readers of the fourth printing (1998) or the fifth printing (2008) or the sixth printing (2013):

page xiii, line 8
change 'Eisenstadt' to 'Eisenstat'
page 17, line 7
change "and I'll go mine" to "(and I'll go mine)"
page 19, line 11
change '1904' to '1903'
page 26, line 8 from the bottom
change '+6' to '+1'
page 26, line 5 from the bottom
change '11n+21' to '12n+19'
page 26, line 2 from the bottom
change '21%' to '14%'
page 30, line 8
change '[38, p. 18]' to '[38, pp. 339–341]'
page 37, line 2 of Example 5
change 'A[i] < x' to 'x < A[i]'
page 39, line 14 from the bottom
change 'Eisenstadt' to 'Eisenstat' (twice)
page 40, line 3 of Example 5a
change 'A[i] < x' to 'x < A[i]'
page 42, line 3 of Example 5b
change 'A[i] < x' to 'x < A[i]'
page 42, last five lines of Example 5b
these lines are all indented by one notch too many
page 42, line 2 of Example 5c
change 'A[i] < x' to 'x < A[i]'
page 43, line 20
change 'A[i] < x' to 'x < A[i]'
page 44, line 5
change 'step 1 until' to 'step 1 until'
page 44, line 29
change 'i=' to 'i ='
page 45, line 5 from the bottom
change 'exit, jumpout, break, or leave' to 'exit, jumpout, break, or leave'
page 46, line 1
change 'Eisenstadt' to 'Eisenstat'
page 47, line 13 from the bottom
change 'a repeat loop' to 'a repeat loop'
page 50, line 7
change 'repeat:' to 'repeat;'
pages 51, 52, 53, 53, 56, 57
change 'integer t; value t;' to 'value t; integer t;'
page 57, line 11 from the bottom
change '$n>0$' to '$n\ge0$'
page 58, line 5
change 'average, will' to 'average will'
page 60, lines 3, 4, 5
change 'all the elements ... greater than v' to 'only elements that are less than or equal to some given value v; the right part A[j+1]...A[n] will contain only elements that are greater than or equal to v'
page 67, line 11
change 'j;' to 'j:'
page 67, line 14
change '1;' to '1 fi;'
page 67, line 3 from the bottom
change 'Hoare' to 'Hoare [13]'
page 74, line 24
change 'j;' to 'j:'
page 80, replace the bottom line by 6 lines
not found: $m\gets\r1$ 2 $a$
     $\r4\gets1$ 1 $a$
     to update$ 1 $a$
found: $\r4\gets B[\r1]$ 2 $1-a$
     $\r4\gets\r4+1$ 1 $1-a$
update: $B[\r1]\gets\r4$ 2 1
page 84, line 3
change Blonde on blonde to Blonde on Blonde
page 84, line 4
change 'March 1966' to 'June 1966'
page 85, in reference [46]
change 'nerve nets' to "nerve nets and finite automata'; also change '3–40' to '3–41'
page 86, line 10
change 'Eisenstadt' to 'Eisenstat'
page 92, line 20
change '$\ne\{x_1,\ldots,x_k\}$ which have' to '$\notin\{x_1,\ldots,x_k}$ that have'
page 92, line 10 from the bottom
change 'integer k; value k;' to 'value k; integer k;'
page 93, line 18 from the bottom
change $q=y_{r-1},y_{r-2},\ldots,y_1$ to $q=y_{r-1}$, $y_{r-2}$, \dots, $y_1$
page 94, line 11
change '[1 : n]' to '[0 : n]' (twice)
page 135, reference [10]
this reference should be the same as [61] on page 86
page 159, line 14
add the statement 'count[0] ← 0;' (to agree with page 164)
page 195, between sections 111 and 117
insert an ellipsis (three vertical dots) as between sections 16 and 95 on page 186
page 250, line 4 from the bottom
change 'decided not be' to 'decided not to be'
page 276, line 6 from the bottom
change 'class L' to 'class L or class R'
page 279, lines 7 and 12
change 'FIFO' to 'LIFO'
page 280, line 13 from the bottom
change '97' to '65'
page 287, line 2 before the footnotes
change z to Z (thrice)
page 288, line 2 from the bottom
change $\theta_2$ to $\theta_0$
pages 294--338
(Several entries in this log have been edited for consistency of style with respect to the others)
page 349, lines 9 and 10
change 'Praktis- che' to 'Prak- tische'
page 354, line 8 from the bottom
change 'labrea' to 'ftp.cs'
page 355, line 12
change 'labrea' to 'ftp.cs'
page 358, new item for the bibliography
Klaus Thull, ``The virtual memory management of PubliC \TeX,'' {\sl TUGboat\/ \bf10},1 (April 1989), 15--22.
page 361, left column
change 'Macdonald' to 'MacDonald' in the Coxeter entry
page 361, left column
change 'x' to 'xii' in the CWEB entry
page 361, right column
change 'Eisenstadt, Stanley C.' to 'Eisenstat, Stanley Charles'
page 362, left column
Guth, Alan Harvey, 337.
page 362, right column
change 'Nicolass' to 'Nicolaas' in the Habermann entry
page 363, right column
add page 322 to the references for Frank Liang
page 364, left column
change 'Marneffe, Pierre-Arnoul de' to 'Marneffe, Pierre-Arnoul Frédéric Guy Donat de'
page 365, right column
change 'Range checks, 30.' to 'Range checks, 30, 32, 59.'
page 366, left column
change 'Rustin, Randall' to 'Rustin, Randall Dennis'
page 366, left column
Scherlis, William Louis, 322.
page 367, left column
change 'Thull, Klaus, 357.' to 'Thull, Klaus, 358.'
page 368, left column
change '139' to 'xii, 139' in the WEB entry

Furthermore, several errors were unfortunately introduced on the cover of the 2013 printing: deer should be decr, and several other elements of the copy should be either italicized or taken out of italics.

I hope the 2013 version is otherwise error-free. But (sigh) it probably isn't. Therefore I will gratefully deposit 0x$1.00 ($2.56) to the account of the first person who finds and reports anything that remains technically, historically, typographically, or politically incorrect. Please send suggested corrections to knuth-bug@cs.stanford.edu, or send snail mail to Prof. D. Knuth, Computer Science Department, Gates Building 1B, Stanford University, Stanford, CA 94305-9015 USA. In either case please include your postal address, so that I can mail an official certificate of deposit as a token of thanks for any improvements to which you have contributed.

I may not be able to read your message until many months have gone by, because I'm working intensively on The Art of Computer Programming. However, I promise to reply in due time.

DO NOT SEND EMAIL TO KNUTH-BUG EXCEPT TO REPORT ERRORS IN BOOKS! And if you do report an error via email, please do not include attachments of any kind; your message should be readable on brand-X operating systems for all values of X.

Don Knuth's home page

Don Knuth's other books

Valid HTML 4.01 Transitional