views:

626

answers:

7

A fair bit is written about literate programming, but I've yet to see any project that uses it in any capacity, nor have I seen it used to teach programming. My sample may small, so I'm looking for evidence that literate programming exists and is successful in the real world.

+8  A: 

I'm not sure it was ever alive. I certainly found Knuth's articles on the subject less than convincing, particularly the use of TeX for the markup language. Actually I think the use of any markup language would probably doom it - the technique cries out for a really powerful IDE, and as far as I know, none ever materialized.

anon
Check out http://webpages.charter.net/edreamleo/front.html, specifically, http://webpages.charter.net/edreamleo/design.html. I'd say it isn't just the IDE, there's got to be more than just the IDE that acts as a stumbling block.
S.Lott
+10  A: 

First, javadoc is a kind of Literate Programming. You are creating documentation and code from a single source. It isn't very good, but it's certainly a form of LP.

Traditional Web/Weave Literate Programming creates documentation and code from a original source files using a specialized markup language. The final document can be elegant and easy-to-work with. The code is the code; but the presentation can focus on important elements, leaving the annoying language-specific machinery for an appendix.

But creating documentation from code is also a form of Literate Programming. The point is to create nice documentation and code from a single source. Java API doc's aren't brilliant, but they're pretty darn good. And including the package overview HTML file is a huge step toward LP from the Java source.

I'd argue that Doxygen, JavaDoc, Epydoc, Sphinx, etc. are a kind of Literate Programming.

Doesn't look dead from the following evidence.

Consider this:

http://en.literateprograms.org/LiteratePrograms:Welcome

http://www-cs-faculty.stanford.edu/~knuth/programs.html

Also consider this IDE for Literate Programming:

http://webpages.charter.net/edreamleo/design.html

Also, consider the original tool suite:

http://www.literateprogramming.com/cweb_download.html

While it hasn't been updated in 2010, it's pretty stable, and doesn't need many updates. It's still being downloaded and used.

Dead is too strong.

Literate Programming is difficult. Jon Bentley's observation: "a small percentage of the world's population is good at programming, and a small percentage is good at writing; apparently [Knuth is] asking everybody to be in both subsets."

Some folks try it and leave because there's one aspect that's particularly hard: debugging. The two-step jump from original source document to program code to traceback output from an error in a unit test is difficult to work with. The line numbers are source code line numbers not original documentation line numbers, and that's a bother.

S.Lott
Since the OP's question related to "the real world", one could argue that evidence of use in academia is of little relevance.
Adam Robinson
Ummmm... What's academic about the answer? Please define "Real World".
S.Lott
I would argue they (doxy etc.) are not LP. If you read Knuth's stuff on LP, you get a nicely structured document who's order is closely controlled by its authour to give the best possible exposition of the code. Doxy etc. simply give you a hyperlinked manual page.
anon
@Neil Butterworth: When I run Javadoc, I get a nicely structured document. Okay, the order is a reference, but it's far, far more literate than "read the source". Or worse, a document that's written independently from the source. Yes, it's weak. But it follows parts of the essential workflow of sole-source, DRY, nicely-formatted.
S.Lott
Neil is correct... the idea behind LP is that you write an article or essay describing your algorithms, etc, and the embedded example code can be extracted and executed.
Mark Harrison
@Mark Harrison: Considering the vast number of LP tools (and approaches) I can't see how it can be absolutely black and white. Look at the LEO editor, which is an outlining text editor/IDE/LP tool. It's not Knuth's CWEB, it's something else. Yet, it seems to count.
S.Lott
@S.Lott, I think the common definition of "literate programming" is as per Knuth. It might be useful to have a common term for "embedded documentation extraction tools" but it's probably better not to overload a well-defined and well-understood term.
Mark Harrison
@Mark Harrison: Bastard Children of Literate Programming was the name I was hoping for. The Literate part is essential in looking at JavaDoc and related tools. As with Knuth-style ("forward") Literate Programming -- the literate doesn't happen by accident or by tool. It happens by carefully thinking through the exposition.
S.Lott
@S.Lott, If you trace the lineage, you will see that embedded comment-style documentation doesn't go back to Knuth, but to something far older. The earliest example of this was ADR (my former employer, fwiw) Autocoder, which did this for RCA and IBM 1401 assembly language circa 1964 or so.<http://www.softwarehistory.org/history/Goetz1.html>
Mark Harrison
@Mark Harrison: That's my point. Knuth rearranged the original "extract" idea into "forward" literate programming; it made sense, since he invented TeX and wrote those books with it. I can't see the firm and absolute division that Knuth style forward LP is the only LP and everything else is unrelated. It seems like alternate approaches to the same objective -- one source, nice results.
S.Lott
+3  A: 

Literate Programming was a big deal back in the 80's and 90's. Like all programming process fads, it had its day until some other great new thing (extreme programming) came along.

Someday a new fad will come along, and people will be on SO asking "whatever happened to extreme programming?"

Of course, like most of the better passed fads, it did leave some traces. Auto documenters like doxygen are a direct result of all the thought put into Literate Programming.

T.E.D.
+2  A: 

The problem with the whole idea is that you have to be a good programmer and a good writer; Knuth may be one of the few people who can do both well.

From a "real world" point of view, there is a heavy dose of YAGNI. Why spend all this time extensively documenting something that might not be around in six months? Knuth's programs have lived for decades, so the investment was worth it for him.

Dan
Good writing may be orthogonal to good programming, but it is not hard to be an *adequate* writer, and every programmer should be working on that. Clear, grammatical, correctly spelled, precise and reasonably concise are the basic benchmarks. Grander, pithy phases and evocative imagery are optional.
dmckee
+1  A: 

With the size of the R community around here I surprised no one has mentioned Sweave yet. This is similar approach, buts seems to take the the approach

Embed the program in the document.

and opposed to Knuth's drive to

Embed the documentation in the program.

In either case, however you write a combined source which is processed to give both document and calculation.

Likewise LaTeX classes and packages can be (and usually are) written with the documentation in a unified file. In the case of something like the memoir class this can print out as considerable pile of dead trees: well nigh a book.

Finally, while today's automatic documentation generators don't have quite the sweeping scope of Knuth's vision I see them as being in the same category.

dmckee
Where, precisely, do you see Knuth's approach to this being embedding documentation in the program? Knuth's original article on the subject (which included the source code to implement it, if memory serves) is mostly documentation, little code by proportion. This sounds to me like "embed program in document".
JUST MY correct OPINION
@ttmricher I think I was being unclear. While Knuth did indeed advocate writing a lot of documentation, the program was the product (i.e. there would be no document without the program). As I see it that is distinct from sweave in which the *document* is the product, and the computation is embedded to insure that the two are kept in sync and to avoid cut-n-pasting the results. Maybe that's just by POV, but there it is.
dmckee
+3  A: 

I saw Knuth's articles on it, and very little else.

I was intrigued by it until I found out what I'd have to write in order to create a literate program: I'd have to write the program and design the documentation in one file, with odd commands. It looked like too much work for most programs, particularly in more experimental programming, where I'd want to try several different things, and where it would represent premature optimization of the documentation. Moreover, I didn't find Knuth's example all that easy to read.

It occurred to me later that this wasn't the only problem. We know what the big problem is in having separate program and documentation files: the documentation, however well done, gets out of date. However, we also know what happens when the documentation is in the form of comments: it gets out of date, although typically not quite as fast. As a result, lots of us try to write generally readable code, and are very good at reading the code. Literate programming seemed to me to break up the usual methods of reading the code, so having people keep the text pieces up to date was vital for understanding the program.

This is more an explanation of why literate programming is dead, but it seems at least mostly dead, in that it's been years since I saw anything about it. It did have an effect, in that it pushed for more structured ways to document in the code and ways to extract meaning from code.

David Thornley
A: 

Only used by people who wrote their own LP systems

Chris Van Wyk of Bell Labs had a series of articles on Literate Programming back in the late 80's. He wrapped up the series with the article referenced below (subscription-only link) with the conclusion that the only people who were using Literate Programming were people who had written their own Literate Programming systems.

http://portal.acm.org/citation.cfm?id=316051&amp;dl=GUIDE&amp;coll=GUIDE&amp;CFID=82297188&amp;CFTOKEN=42986299

Mark Harrison