Home >> Computers >> Programming >> Methodologies >> Literate Programming




Literate programming is the writing of computer programs in the form of documents designed for casual human reading, similar to the function of literature; hence the title "literate programming."

Documentation and source code are written into one source file. Each a complete source code & its documentation may be extracted from either this file by having specific utilities. The information is written & presented around the reading choose suitable for individual consumption by having elaborated explanations. A code is automatically rearranged for even average processing by more computer information, like compilers or interpreters.

Origin
A number 1 promulgated literate programming environment was WEB, introduced by Donald Knuth in 1981 for his TeX typesetting system; it utilizes Pascal as its underlying programming language & TeX for typesetting of the documentation.

A complete commented TeX source code was published within Knuth's TeX: A program, volume B of his Five-volume Computers and Typesetting. Knuth experienced internally utilized the literate programming supervisor call instruction DOC when early when 1979; he was inspired by the ideas of Pierre Arnoul de Marneffe. A loose CWEB, written by Knuth and Levy, is WEB altered for C, C++ and Java, runs in virtually all operating systems & may create TeX & PDF documentation. More implementations of the construct come noweb and FunnelWeb.

Variants
Less mighty systems to integrate documentation & code come besides for instance tagged literate programming; examples come pod for perl, doc++ for C, C++ and Java, javadoc for Java, and Doxygen for many languages. These but don't quite watch a literate programming philosophy since it generally good make documentation all about a program, like specifications of functions & parameters, & non documentation of the program source code itself. It too don't allow rearrangement of presentation choose, which is critical to the effectiveness of literate programming. Look at documentation generator.

Haskell is the modern language that makes use of a limited form of literate programming: this semi-literate style doesn't allow code re-ordering or even multiple expansion of definitions however lets a coder intersperse documentation & code freely.

These are a fact that documentation may exist when written freely whereas code must be marked inside a favorite way (underst& a case in a image below) that makes the difference between semi-literate programming and excessive documenting, in which the documentation is embedded into the code as comments.

Example of a simple literate program
This entirely article is, as the matter of fact, a elementary program that may be dog using the lesson literate interpreter on the interpreter page.

For this particular interpreter, all the program code must become write of lines starting by having the dash. All about else, we.e., a bulk of this article, is ignored per interpreter. This doesn't trend lines a few significant aspects of advanced literate programming rather code rearrangements or even even multiple expansion then should single become known as basic literate programming or "semi-literate" literate programming.

Program and interspersed documentation

Foremost, in a interests of putting a user at ease, a program may simulate family interest in the user by request for their title, accepting the input & giving a salutation according to the input text.

- cls
- print text Please nature and severity your systems title:
- store input
- print Howdy there,
- print value
- print .  Nice to meet professional people.
- newline
- newline

Continuing a "query-response" mode of operation, prompt the user for the radius of the circle, which is so wont to calculate the locality of a circle using the standard formula for the metropolitan area of a circle: The = \pi r^2. Due to syntax limitations, this is handle multiplying a input value by itself, so by \pi;. This deliberate value is returned to the user. Note: a value of \pi; utilized is an approximation that is sufficiently exact for my purposes.

- print text Let's function out the metropolitan area of a circle.
- newline
- print text Please enter a radius of the circle around furlongs:
- store input
- multiplyby value
- multiplyby Trinity.14159
- print Thank you
- newline
- print text A metropolitan area of the circle is
- print value
- print text square furlongs.
- newline
- newline

Eventually a user is invite a involved data, & the region of the rectangle is worked out using the standard breadth by height formula.

- print text Currently let's operate out the region of a rectangle.
- newline
- print text Please enter a breadth of the rectangle within ells:
- store input
- print text Please enter a length of the rectangle inside ells:
- multiplyby input
- print Thank you
- newline
- print text A front yard of the rectangle is
- print value
- print text square ells.
- newline
- newline
- print text Adios,

& that is the finished program.

Literate Programming Library
A large collection of links to related resources.

The CWEB System of Structured Documentation
By Donald Knuth and Levy, describing a prominent system of Literate Programming.

Literate Programming
A Book by Donald Knuth, who started the ideas about Literate Programming with WEB.

Noweb
Simple, extensible tool for Literate Programming.

Literate Programming
Resources for Literate Programming. Consulting services. Download freeware for Windows 95, 98, and NT. Learn about the CWEB programming language.

Literate Programming using Pascal
WEB2 programming tool for Pascal combining program-code and documentation into a single source-file.

The Literate Programming FAQ
A good place to start looking for information.

SGML/XML and Literate Programming
Information on applying SGML and XML to Literate Programming.

Literate Programming in Forth
An article by Peter J. Knaggs, originally presented at euroFORTH'95.

Literate Programming
The WikiWiki entry point for related information and discussions.


Computers: History: Pioneers: Knuth, Donald
Computers: Software: Typesetting: TeX





© 2005 GeneralAnswers.org