4 ms·
Is the Knuth book on literate programming any good? Anyway I thought this article would have been better with a few examples. I'm still not any closer to unde
by rwmj 10y ago
Is the Knuth book on literate programming any good?
Anyway I thought this article would have been better with a few examples. I'm still not any closer to understanding how the tangling process works.
- pfortuny 10y agoIt is interesting although the examples are a bit convoluted. However, once you read it you understand that LP is probably only useful for single-person projects (because each programmer "thinks" each problem in his own way).
- gjm11 10y agoYes, the Knuth book is good, but note that what it is is a collection of papers, most of which are not really about literate programming. Some of them predate literate programming as such; e.g., there's a classic called "Structured programming with go to statements". There's the original article from 1984 that introduced literate programming. There are two "Programming Pearls" columns from CACM; the first is another introduction to literate programming, and the second is a not-entirely-trivial program for counting common words in a file -- followed by a review by Doug McIlroy which is very well worth reading in its own right. There are extracts from the TeX and METAFONT (literate) source code. There's the classic "The Errors of TeX" paper, as well as the whole TeX error log up to 1991. (And a few other things, but I think the ones I listed above are the most interesting.)
- Mikhail_Edoshin 10y agoI've read Knuth's article on this and here's my thoughts. It's meant to be used with a single language (Pascal), which is sometimes good (because the tool really understands Pascal and can parse these code snippets to produce a cross-reference), but it's also a curse, because many of the tool's constructs are actually workarounds for Pascal shortcomings. Also, it only generates a single file, but today's projects are both multi-file and multi-language. So it's a bit dated. I think the idea itself is so simple it doesn't really need any extensive book. Basically you take any text preparation system and add three elements: a code fragment, a reference to a code fragment, and a file, which is a fragment that will be written to disk. (I myself use such a system based on reStructured Text. I want to post it on Github when it's ready, but it's not there yet, so I cannot show exactly how it works. But I use it to write a moderately complex personal project with C and Python mostly, and all the tooling, e.g. Makefiles. I found it very helpful; it does make the code much cleaner, that is it strongly urges you to. And it's invaluable when you want to remember why you did things that way.)
- crististm 10y agoIsn't Knuth's CWEB used for C?
- Mikhail_Edoshin 10y agoCWEB is for C and the original WEB was for Pascal. (C is a good fit, by the way, because you can use #line directive to make the compiler to report the line numbers in your original literate files instead of the irrelevant line numbers in generated files.) But as far as I remember it still produces a single C file and a single TeX file.
- e12e 10y agoWhen experimenting with NOWEB and Java (1.3 I believe) I discovered that one of the things that those LP systems did was encourage something like macro based code re-use, somewhat "lifting" the rather basic language up towards something a little more high level. This was good and bad; bad like unhygienic macros can be bad. As far as I could figure out it was a poor match for OO/"inheritance oriented" programming. It was a better match for procedural style programming - "writing C in java" - then the LP "macros" didn't confuse things. But when mixing OO-style java, I found things seemed to become uncomfortably verbose. NOWEB might in some ways be the worst of both worlds - it knows (and cares) nothing about the programming language - but that also means blocks can't be parameterized. This is annoying if you're using variables to hold iterators and state (traversing a graph stored in arrays as edge/node lists etc). You end up with dangerous variable name re-use or code duplication (and too big code blocks).
- eru 10y agoHave a look at http://www.literateprogramming.com/adventure.pdf http://www.literateprogramming.com/adventure.pdf for another example. (I think the source-document that the pdf is made from is also available.)