Bubbles_glow

≡ Hypertextopia Manifesto ≡

 
Corner_fold
  • Citation
  • Description
  • Explanation
Picture_7_catalog
 
Flowchart_grey_24

Literate Programming: An Example

In 1981, Donald Knuth, the famous computer programmer and professor, developed a philosophy that he calls “Literate Programming”. Starting from the premise that a good software program should read like a good work of literature, the programmer becomes responsible for writing the source code to be as interesting and informative as possible for readers. In one stroke, by reclaiming the computer program as an art form that a person might want to read, as opposed to a series of instructions that are only comprehensible to a computer, Knuth claims that literate programming will produce programs of superior technical and artistic merit. I agree with him. There are scores of reasons why in this age of complexity, when the cost of software maintenance can be as high as 80% of the total, a literary approach will prove to be more elegant and more cost effective. Programs addressed to a human are far easier to comprehend and tend to have superior structure, making them cheaper to understand and maintain. Literate programming borrows the forms of exposition and introduction from traditional literature, borrows the structure of an essay, mutates them slightly, and employs them towards the pragmatic goals of writing software.


 

From Donald Knuth. “Literate Programming (1984)” in Literate Programming. CSLI, 1992, pg. 99:

Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.

The practitioner of literate programming can be regarded as an essayist, whose main concern is with exposition and excellence of style. Such an author, with thesaurus in hand, chooses the names of variables carefully and explains what each variable means. He or she strives for a program that is comprehensible because its concepts have been introduced in an order that is best for human understanding, using a mixture of formal and informal methods that reinforce each other.