Donald Knuth. “Literate Programming ()” in Literate Programming. CSLI, , pg. I believe that the time is ripe for significantly better documentation of . Literate programming: Knuth is doing it wrong. Literate programming advocates this: Order your code for others to read, not for the compiler. Literate. What is Literate programming? Literate programming is a style of programming invented by Donald Knuth, where the main idea is that a program’s .

Author: Dikora Mudal
Country: Paraguay
Language: English (Spanish)
Genre: Technology
Published (Last): 11 March 2009
Pages: 246
PDF File Size: 2.75 Mb
ePub File Size: 15.3 Mb
ISBN: 878-7-21938-673-1
Downloads: 7923
Price: Free* [*Free Regsitration Required]
Uploader: Daigore

The fundamental elements of any computer program are, perhaps not surprisingly, time and space. Scattered in amongst the program code are comments which describe the various parts of the code.

Programminf main idea is to treat a program as a piece of literature, addressed to human beings rather than to a computer. Modules have three parts: When the last order of the subroutine has been executed the machine proceeds to execute the order in the program that immediately follows. Rather than to present the program in the form in which it will be compiled or executedand to intercalate comments to help humans understand what is going on and which the programmng will kindly ignorethe presentation focuses on explaining to humans the design and construction of the program, while pieces of actual program code are inserted to make the description precise and to tell the computer what it should do.

Literate programming – Wikipedia

This misconception has led to claims that comment-extraction tools, such as the Perl Plain Old Documentation or Java Javadoc systems, are “literate programming tools”.

But sigh it probably isn’t. Innovative ideas, critical technical knowledge, algorithmic solutions, and unusual coding constructions are clearly documented. The whole concept of code sections, indeed structured programming, is to reduce the amount of text that must be read in order to determine what a piece of code is doing. This may seem like a trivial change, but in fact literate programming is quite different from other ways of structuring software systems.


A classic example of literate programming is the literate implementation of the standard Unix wc word counting program. As I was writing TeX I was using for the second time in my life ideas called “structured programming”, which were revolutionizing the way computer programming was done in the middle 70s. I discovered from reading some of the articles, you know, I could find three bugs in a program that was proved correct.

Anything that is logically inuth of the section should be moved into it, thereby reducing the complexity of the code where it is referenced. This book presents a selection of modern rendering algorithms through the documented source code for a complete rendering system. Literate Programming in WEB”.

Thus the program can be described in a logical manner. By combining the two, we can develop a style of programming that maximizes our ability to perceive the structure of a complex piece of software, and at the same time the documented programs can be mechanically translated into a programmibg software system that matches the documentation.

Listings generated in PDF format include hypertext links.

The most obvious and natural way to do this is to suppress the program text for those inner levels, leaving an outline of the outer level, while the inner levels may be specified and documented elsewhere; this is a bit like introducing subroutines for the inner levels, but without the semantic implications that that would have. This of course helps pfogramming.

If we made these variables local to main, we would have to do this initialization explicitly; however, C globals are automatically zeroed. Parts of the program that belong together logically should appear near to each other in the description, so that they are visible from the part of the documentation that discusses their function. The typographic tools provided by TeX give us an opportunity to explain the local structure of each part by making that structure visible, and the programming tools provided by languages like C make it possible for us to specify the algorithms formally and unambiguously.


I believe that the time is ripe for significantly better documentation of programs, and that we can best achieve ;rogramming by considering programs to be works of literature. In literate programming the emphasis is reversed.

For example, suppose that you want to define something like The code section is a form of data reduction in that the litertae name is a placeholder representing the code contained in that section.

The simplest form of subroutine consists programmijg a sequence of orders which can be incorporated as litsrate stands into a program. It is designed so that when its task is finished it returns control to the master routine at a point immediately following that from which it was called in.

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. These macros are similar to the algorithms in pseudocode typically used in teaching computer science.

Literate programming

Choose class names, function names, and variable names wisely. Literacy in programming means different things in different circumstances.

Indeed we believe that deep understanding of a small number of algorithms in this manner provides a stronger base for further study of computer graphics than does a superficial understanding of many.