Literate Programming Matters
github.com
github.com
And in terms of the gist of Reg's essay, I think the single line that best cuts to the heart of it is: "[...] while David presents the concepts of literate programming and elegant programming as a dichotomy, I think they're orthogonal." Bingo.
@raganwald: I'd be curious to hear more about what sort of "literate programming tool that transforms the source directly" you were hankering for. Not CWEB style?
An aspect I didn't discuss is that when we write in English the usefulness of the text is then subject to the ability of the author to write clear, logical, concise (hopefully beautiful & elegant) English. So it's not surprising, to me at least, that the best literate programs I've read are not online but in books.
Comes down to traditional OOP being a tree formed by belongs-to relationships between entities and responsibilities, but Cafe au Life having a many-to-many relationship.
p.s. What are your thoughts on Cafe au Life? Is this (In Your Humble Opinion) idiomatic CoffeeScript? Is this how you envisioned Docco being used? Feedback most welcome...
In addition to the benefits mentioned there are at least 3 others I can site.
First, since you spend time explaining why you are writing the code and your thoughts on the design and implementation you naturally discover edge cases, missing cases, and bugs. As a result, the quality of the code is higher.
Second, if you program in a team that does code reviews, the team can see your approach to the solution and the reasons. They can critique your work at a more profound level. If the code review happens before accepting the change commit, the quality of the code is higher.
Third, code lives. Sourceforge is a gravesite of hundreds of thousands of programs that have died because the authors are no longer maintaining the code. New users are confronted with a source tree of tiny files which they are unable to understand and therefore unable to modify and maintain.
I have the "hawaii test" criteria. If you can hire a new developer, give them your program, send them on a 2 week, all expense paid vacation to hawaii, and when they return they can modify and maintain the program as well as the original authors, then you have a fully literate program.
As for the question of debugging, I find that it is no different. Generally the source of bugs are the same (e.g. using copy/paste and failing to properly fix the copy).
Literate development, for me, takes on two different styles depending on the language.
In a language that allows a read-eval-print loop, like lisp, it is trivial to work in emacs with a command line in one buffer and the literate sources in another buffer. You just point at the changed code and evaluate it immediately in the other buffer. It is very productive.
In a language like Java that is a pure compile environment I create a makefile that extracts the code from the literate document into the proper com.foo.baz.... source tree, compiles the code, and runs the test regression suite. This generally takes less than a minute or two for most reasonably sized Java programs. So I make a small set of changes, save the buffer, run 'make', and see if the tests pass. For TDD programming I find this works very well.
My last large program was 60000 lines of Lisp in a latex literate file. Tex'ing the file with all of the literate documentation generated 6000 pages. The technology scales quite well.
Learning literate programming is like learning lisp. You keep wondering why anyone would program this way until you suddenly "get it". Once that happens you wonder why anyone could program any other way.
Tim Daly
If I remember correctly, I once had two C preprocessors that did just that, without the rest of the literate programming features. (Found a paper for one of these: http://page.mi.fu-berlin.de/prechelt/Biblio/refinement.pdf)
Here, even when I have the userscript[0] to show the full domain names so I know when something is being posted by a user of a company instead of the company itself, it still just shows "github.com" leading me to think it's Github and crew talking about literate programming.
(I'll admit, I saw it was raganwald and that gave it away, but still).
[0] https://github.com/johngibb/Hacker-News--Show-Subdomains
As presented in the essay, an organization of code for the purpose of explaining the code to a new programmer might differ from an organization for the purpose of maintaining the program by people familiar with its design.
The premise of the original Literate Programming was to use meta-annotations to write documentation that showed the code organized for explanations, while leaving the original in a form suitable for the machine and/or for experienced programmers.
Lacking this tool, if we use techniques like AOP to reorganize the program for explanation, we might be making things more difficult for the experienced programmer, who does not find all of the methods for a square in one place in the Square class’ definition.
Literate programming doesn't need to be all-or-nothing!
Merely having "English narrative" does not get you to literate programming. You can call it a "literate programming style", which is fine, but it's important to understand what true "literate programming" actually requires:
'Literate programming tools are used to obtain two representations from a literate source file: one suitable for further compilation or execution by a computer, the "tangled" code, and another for viewing as formatted documentation, which is said to be "woven" from the literate source.' http://en.wikipedia.org/wiki/Literate_programming
Tools like Javadoc are related to the second part of literate programming above, and allow for creating some formatted documentation from source code. ( http://en.wikipedia.org/wiki/Javadoc ) They don't get you all of the second part of a literate "woven" program, though, which includes text with all of the source of a program in a format suitable to be read like a book or literary essay.
Tools like Javadoc also have absolutely nothing to do with the first idea in literate programming (above), which is to have an ultimate source document where code is organized and presented in manner best suitable for human understanding, not in manner that's tailored for machine compilation (e.g., for machine-compilation the code may need to be separated into different units or files, whereas in literate source that would not be done unless it were an aid to understanding).
All that is not to say that trying to be a little more "literate" with comments in regular source code is not a good thing. But it's important to understand that "literate programming" is a clearly defined practice that requires much more than good-quality commenting.
I'm not sure whether this is an issue merely for the new versus the experienced programmer. It is an issue I see as even more important to debugging, where all the debugging tools a programmer uses are geared towards working with the compilable codebase, not the literate one. To make things work smoothly you need to be able to edit the compilable codebase and have changes be reflected in its untangled (i.e., literate) form.
The first criticism is perhaps more of literate programming, the concept, than this example. I personally find it difficult to read when each line of code is disjointed by comments. I guess I prefer the chunk size to be larger; a coarser granularity.
Some of these comments really seem unnecessary. for example:
# Export `Cell`
_.defaults exports, {Cell}
I think that is obvious enough that the code is "exporting" 'Cell'. I couldn't tell you why though.My second criticism is that it seems comments are all too often of the "what" variety. Simply translating the code to english. That's not really very helpful. Once someone has some grasp of the programming language being used, the "what" is right there in the programming language. No need to restate it in another language.
What is helpful is the "why" of a chunk of code. I can read plain as day what it is doing. But why is the code doing that? Why was it written? Why is it necessary to do this particular thing? To me, at least, that seems much more helpful.
I feel my commenting has gotten much better since I started paying attention to when I was writing a "what" comment, caught myself, and wrote a "why" comment instead.
I agree, but if you read any of Knuth's literate programs, they are not at all line-by-line commentaries.