Thoughts and links about programming, by


Literate Programming with Lguest
Posted on Friday, January 4, 2008.

Norman Ramsey defines literate programming as “the art of preparing programs for human readers.”

Donald Knuth invented literate programming when Tony Hoare (inventor of quicksort) challenged him to publish TeX (the program). In his article introducing literate programming, Knuth explained:

I believe that the time is ripe for significantly better documentation of programs, and that we can best achieve this by considering programs to be works of literature. Hence, my title: “Literate Programming.”

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.

You can't beat literate programs for completeness. In a good literate program, every line is explained in clear prose. Having to explain the program using English often forces the program itself to be more clearly written too.

Good, full-size literate programs are rare. Knuth's book TeX: The Program and Chris Fraser and David Hanson's book lcc, a Retargetable Compiler for ANSI C are two, but I'd love to hear about more.

Today's link is to the literate version of lguest, an up-and-coming x86 virtual machine monitor for Linux. To first approximation, lguest is like Xen or VMware but simpler.

(Comments originally posted via Blogger.)

  • Ralph Corderoy (July 4, 2010 6:03 AM) Fraser and Hanson's follow-up to lcc, C Interfaces and Implementations, is also literate, as mentioned in their preface.