Well gentlemen, I have found your discussion very interesting |
Wow, I didn't expect anyone to read all this...
LP is something I am not familiar with, but without rooting around the internet researching it, I am assuming from how you talk about it that you (@exception) are using it as an extra layer of abstraction in the design process that also enhances the documentation. |
Well, Zeita already posted two quotes, let me try to give a short overview with another from it's inventor, D.E. Knuth:
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. |
So, the main idea behind LP is a new understanding of what programming actually means, with a very close relation to "documentation". But to provide for this task, it has another functionality: an additional layer of indirection on a pre-compilation basis. The "literate source", containing code- and documentation chunks, does not have to provide the source code in the order it will be "untangled" in the final sourcefile (just like functions have to be declared in the order they are called). For example, you could write
1 2 3 4 5 6 7 8 9 10 11 12
|
<<demonstration of LPs indirection>>=
point p, q;
try
{
if(p==q)
<<delete one of the points, since they are the same>>
else
<<create a directed line from p to q>>
}
catch(...)
<<perform cleanup if anything has gone wrong>>
@
|
The code chunks (maked by <<...>>) used here can be defined anywhere in the document, using <<...>>=/*code*/@. So if you see it fit, you can make a chapter "Error Handling", where the cleanup code goes (e.g. if it is a scientific paper and the readers won't care much).
Defining a name twice expands it, so you could now write
1 2 3 4 5 6
|
<<perform cleanup if anything has gone wrong>>=
if(p==0)
@ This might happen if $some complicated latex formula$, as shown by \cite{supervisor}
<<perform cleanup if anything has gone wrong>>=
delete p;
@
|
...which would be printed in this order in the document, neatly layouted with explanation, and produce
in the untangled source. This opens a whole new possibility to let the code "document itself", by writing pseudo-code in the chunk names, giving the reader a faster way to go where he wants to go (e.g. to fix a bug): the chunks are linked when generating a pdf document as documentation (otherwise they are referenced by page number+ID). (One could jump in an IDE, but only on the function basis. And if you don't exactly know where the problem is, you can find it quicker by having an overview of the whole application an the abstraction level you need).
In general, documentation is often over used |
Well, I'd rather say it is misused. The documentation I have to write and I get is absolutely unusable, not being up-to-date or complete being two of the main issues. I don't need such a documentation at all. On the other hand, if it were complete, up-to-date and written well, I think it would make a lot of jobs easier. LP helps to achieve all of these aims (by having all code contained in the documentation it urges the author to make it complete; by having the documentation opend when editing the code it urges the author to make it up-to-date; by having LaTeX' formatting power, it urges the author to make it clean, clear and 'pretty').
Another point is that it should be distinguished between different kinds of documentation: API, maintainer, end-user and administrator (whom did I forget?) all have different needs. Again, LP could provide for all (even the advanced end-user will be interested in an abstract overview of the applications structure).
I suspect, from your comments about LP, that any code maintenance would require changing the LP code which would ripple through to changes in the source code. |
To stay "literate", yes. But the extracted source is not distinguisable from "traditional" code, so if you don't care about the documentation, no.
knowledge of LP is not widespread |
That's right. But as I said, the code can be maintained without any LP knowledge, if required. So little risk is involved, really. Someone who can code in C++ can grasp the tool usage in less than a day, the actual "art" of LP is of course another matter. But the latter wouldn't be required so much for mainenance, when you only have to change something, not write it completely new.
Two things I'd like to make clear, if they weren't already:
(a) I don't want to talk anyone into using LP. It may have seemd that way in the beginning of the discussion, but that was due to some rather... controversal statements on both sides, I think
(b) When I first had to use LP, I pretty much had the same arguments against it Zeita has. I was "forced" to use it at university (had it not been my "best" prof, I would have chosen another course). Only when I had used it some time I accepted the fact that there are methologies other than the "traditional" way which are worth consideration. So I do understand your doubts. But I invite you to give it a try, when you have the time. It's a new programming experience.