Skip to content

Literate Programming

Andrew Binstock’s recent interview with Donald Knuth has received a lot of attention for his comments about unit testing, multicore, and other things of which Knuth is skeptical, but I was more interested in his comments on the topics which he endorses. Knuth is the originator of (amongst many other things) literate programming. One way to think about literate programming is that it turns the notion of commenting on its head. In a traditional program, you use relatively few comments, and partition the comments with the limiters. Literate programs are mostly English text, with compilable code delimited.

Knuth seems uncertain as to why literate programming hasn’t really taken off:

Jon Bentley probably hit the nail on the head when he once was asked why literate programming hasn’t taken the whole world by storm. He observed that a small percentage of the world’s population is good at programming, and a small percentage is good at writing; apparently I am asking everybody to be in both subsets.

Well, sure, but even if one assumes that 1/10 of working programmers are decent at their job, and 1/10 of those can express themselves in English and a reasonably clear manner, that’s not really enough to account for the low use of literate code. There are number of good bloggers and technical publication authors, and literate coding would seem to be well suited for these tasks. Maybe we just need some better examples to get the ball rolling.

You don’t have to read it many books on software development before you’ll encounter one with source code examples which produce erroneous results, or even fail to compile altogether. It’s an absurdly common error. Taken to an extreme, it can be maddening. In the past month or so, I’ve been reading the preprints at Bruce Eckel and Jamie King’s new book on LINQ. One interesting thing about this book is that in the process of writing it, the authors have developed a build system which builds all of the source code examples, including verifying the in-line assertions, and even goes so far as to ensure that the examples which are not supposed to build at all really do fail to compile. The finished book may not be flawless, but the examples are going to work.

I think it’s a perfect application of literate programming; I cannot think of a better solution to this problem.

{ 1 } Comments

  1. Jakob | May 11, 2008 at 12:00 pm | Permalink

    I think one problem of literale programming is the lack of good and easy tools. Hypertext was a good idea long before WWW but it did not really succeed until there was Mosaic. All literale programming systems I know are limited to a specific programming language and/or a specific typesetting system and driven only by a small group of developers.

Post a Comment

Your email is never published nor shared. Required fields are marked *
Close