Literate programming

[1] The approach is used in scientific computing and in data science routinely for reproducible research and open access purposes.

[4] Literate programs are written as an exposition of logic in more natural language in which macros are used to hide abstractions and traditional source code, more like the text of an essay.

[1] The practice of literate programming has seen an important resurgence in the 2010s with the use of computational notebooks, especially in data science.

These arbitrary explanatory phrases become precise new operators, created on the fly by the programmer, forming a meta-language on top of the underlying programming language.

A preprocessor is used to substitute arbitrary hierarchies, or rather "interconnected 'webs' of macros",[7] to produce the compilable source code with one command ("tangle"), and documentation with another ("weave").

The preprocessor also provides an ability to write out the content of the macros and to add to already created macros in any place in the text of the literate program source file, thereby disposing of the need to keep in mind the restrictions imposed by traditional programming languages or to interrupt the flow of thought.

The meta-language capabilities of literate programming are also claimed to facilitate thinking, giving a higher "bird's eye view" of the code and increasing the number of concepts the mind can successfully retain and process.

[8] Knuth also claims that literate programming can lead to easy porting of software to multiple environments, and even cites the implementation of TeX as an example.

However, because these tools do not implement the "web of abstract concepts" hiding behind the system of natural-language macros, or provide an ability to change the order of the source code from a machine-imposed sequence to one convenient to the human mind, they cannot properly be called literate programming tools in the sense intended by Knuth.

The <<*>> symbol stands for the "root", topmost node the literate programming tool will start expanding the web of macros from.

[1] In a noweb literate program besides the free order of their exposition, the chunks behind macros, once introduced with <<...>>=, can be grown later in any place in the file by simply writing <>= and adding more content to it, as the following snippet illustrates (+ is added by the document formatter for readability, and is not in the code).

[16] The free CWEB, written by Knuth and Silvio Levy, is WEB adapted for C and C++, runs on most operating systems, and can produce TeX and PDF documentation.

The LaTeX listings package provides a lstlisting environment which can be used to embellish the source code.

It can be used to define a code environment to use within Haskell to print the symbols in the following manner: which can be configured to yield: I had the feeling that top-down and bottom-up were opposing methodologies: one more suitable for program exposition and the other more suitable for program creation.

Again, I did this in the interests of simplicity, because I noticed that most applications of multiple parameters could in fact be reduced to the one-parameter case.

Literate Programming by Donald Knuth is the seminal book on literate programming.