Literate programming, good/bad design methodology

design-patternslanguage-designliterate-programming

I have recently found the concept of literate programming. And I found it rather intriguing. Yet I have not been encountered with claims that it is a bad way to structure a program. It seems not covered many places. Not even here could I find any questions regarding this.

My question is not about its flaws or ways of handling documentation. I consider the documentation a side-effect of what it would mean for the flow of literate programming. I know that the design was originally intended for easy documentation as well as the concept of forward programming flow.

The concept of dividing the problem into small sentence based problems seems to be really a brilliant idea. It will thus ease the understanding of the program's flow.

A consequence of the literate design method is also that the number of functions required will be limited to the imagination of the programmer. Instead of defining a function for a certain task, it could be created as a scrap in the literate method. This would yield automatic insertion of the code, instead of a separate function compilation and subsequent requirement of an inter-procedural compilation optimization step to obtain the equivalent speed. In fact Donald E. Knuth first attempt showed an inferior execution time, due to this very fact. I know that compilers can be made to a lot of this, however this is not my concern.

So I would like to get feedback of why one should consider this a bad/good design methodology?

Best Answer

This would yield automatic insertion of the code, instead of a separate function compilation and subsequent requirement of an inter-procedural compilation optimization step to obtain the equivalent speed

This is irrelevant. Has been for decades. You can remove it from the question, since it makes no sense with modern compilers to subvert their optimizers.

So I would like to get feedback of why one should consider this a bad/good design methodology?

There is no downside to literate programming. (I expect dozens of -1 votes for that sentiment.) As a practitioner, I've never seen any problems.

There are some arguments against which all amount to "programming in a higher-level language is be subverted by tweaking the resulting code." Right. In the same way that programming in C++ is subverted by tweaking the .o file that gets produced. It's true, but irrelevant.

Writing literate programs merely means combining high-level and detailed (code-level) design into one document, written with a suitable toolset that produces compiler-friendly files and people-friendly files.

When Knuth invented literate programming, mainstream OO languages didn't exist. Therefore a great deal of the original web and weave tools allowed him to create class-like definitions for abstract data types.

Much of that is irrelevant nowadays. Literate Programming tools can be quite simple if they're focused on modern, high-level object-oriented (or functional) programming languages. There is less need for elaborate workarounds because of the limitations of C (or Pascal or Assembler).

The approach to writing literate programs is no different from the approach to writing illiterate programs. It still requires careful design, unit testing, and neat coding. The only extra work is writing explanations in addition to writing code.

For this reason only -- the need to write coherent explanations -- literate programming is difficult for some programmers. There are a fair number of programmers who are successful (their code passes all the unit tests, is neat and easy to understand) but can't seem to write a coherent sentence in their native language. Don't know why this is true.

There are a very large number of programmers who appear to be only marginally successful and then only by accident. (There are enough bad questions in Stack Overflow that indicate that many programmers struggle to even grasp the fundamentals.) For programmers who ask largely incoherent stack overflow questions, we know they can't really do a good job of literate programming, because they can't do a good job of programming.

Related Topic