Copyright © Philip M. Parker, INSEAD. Terms of Use.

LITERATE PROGRAMMING

Specialty Definition: LITERATE PROGRAMMING

DomainDefinition

Computing

Literate programming Combining the use of a text formatting language such as TeX and a conventional programming language so as to maintain documentation and source together. The program is sometimes marked to distinguish it from the text, rather than the other way around as in normal programs (the inverse comment convention). Perl's literate programming system is called pod. (1998-12-18). Source: The Free On-line Dictionary of Computing.

Source: compiled by the editor from various references; see credits.

Top     

Specialty Definition: Literate programming

(From Wikipedia, the free Encyclopedia)

Literate programming is a certain way of writing computer programs. It is seen as communications to human beings, as works of literature, hence the name "literate programming."

Documentation and source code are written into one source file. The compilable source code and the formatted documentation can be extracted from this file with specific utilities.

The information is presented in a reading order suitable for human consumption. The code is automatically rearranged for computer execution.

Origin

The first published literate programming environment was WEB, introduced by Donald Knuth in 1981 for his TeX typesetting system; it uses Pascal as its underlying programming language and TeX for typesetting of the documentation.

The complete commented TeX source code was published in Knuth's TeX: The program, volume B of his 5-volume Computers and Typesetting. Knuth had internally used a literate programming system called DOC as early as 1979; he was inspired by the ideas of Pierre Arnoul de Marneffe. The free CWEB, written by Knuth and Levy, is WEB adapted for C, C++ and Java, runs on most operating systems and can produce TeX and PDF documentation. Other implementations of the concept are noweb and FunnelWeb.

Variants

Less powerful systems to integrate documentation and code are also sometimes labeled literate programming; examples are pod for perl, doc++ for C, C++ and Java, and javadoc for Java. These however do not quite follow the literate programming philosophy since they typically just produce documentation about the program, such as specifications of functions and parameters, and not documentation of the program source code itself.

Example of a simple literate program

This whole article demonstrates one method of implementing the idea of literate programming. You can copy it and run it using the example literate interpreter on the interpreter page.

Note that all program code in this article is on lines which start with a dash. Everything else is assumed to be comments and will be ignored by the interpreter.

Firstly, in the interests of putting the user at ease, the program will simulate personal interest in the user by asking for their name, accepting the input and generating a greeting based on the input text.

- cls
- print text Please type your name:
- store input
- print Hello there,
- print value
- print .  Nice to meet you.
- newline
- newline

Continuing the "query-response" mode of operation, prompt the user for the radius of a circle, which is then used to calculate the area of a circle using the standard formula for the area of a circle: A = πr2. Due to syntax limitations, this is done by multiplying the input value by itself, then by π. This calculated value is returned to the user. Note: the value of π used is an approximation that is sufficiently accurate for our purposes.

- print text Let's work out the area of a circle.
- newline
- print text Please enter the radius of the circle in yards:
- store input
- multiplyby value
- multiplyby 3.14159
- print Thank you
- newline
- print text The area of the circle is
- print value
- print text square yards.
- newline
- newline

Finally we'll ask the user for the required information and work out the area of a rectangle using the standard width by height formula.

- print text Now let's work out the area of a rectangle.
- newline
- print text Please enter the width of the rectangle in yards:
- store input
- print text Please enter the length of the rectangle in yards:
- multiplyby input
- print Thank you
- newline
- print text The area of the rectangle is
- print value
- print text square yards.
- newline
- newline
- print text Goodbye,

And that's the program finished.

References

Source: adapted by the editor from Wikipedia, the free encyclopedia under a copyleft GNU Free Documentation License (GFDL) from the article "Literate programming."

Top     

Crosswords: LITERATE PROGRAMMING

Specialty definitions using "LITERATE PROGRAMMING": Donald KnuthLitProgNOWEB. (references)

Top     

Commercial Usage: LITERATE PROGRAMMING

DomainTitle

Books

  • Computational character processing : character coding, input, output, synthesis, ordering, conversion, text compression, encryption, display hashing, literate programming : bibliography (reference)

  • Literate Programming (reference)

    (more book examples)

Source: compiled by the editor from various references; see credits.

Top     

Frequency of Internet Keywords: LITERATE PROGRAMMING

The following statistics estimate the number of searches per day across the major English-language search engines as identified by various trade publications. Hyperlinks lead to commercial use of the expression at Amazon.com.
 
ExpressionFrequency
per Day

literate programming

3
Source: compiled by the editor from various references; see credits.

Top     

Alternative Orthography: LITERATE PROGRAMMING


Hexadecimal (or equivalents, 770AD-1900s) (references)

4C 49 54 45 52 41 54 45      50 52 4F 47 52 41 4D 4D 49 4E 47

Leonardo da Vinci (1452-1519; backwards) (references)

    

Binary Code (1918-1938, probably earlier) (references)

01001100 01001001 01010100 01000101 01010010 01000001 01010100 01000101 00100000 01010000 01010010 01001111 01000111 01010010 01000001 01001101 01001101 01001001 01001110 01000111

HTML Code (1990) (references)

&#76 &#73 &#84 &#69 &#82 &#65 &#84 &#69 &#32 &#80 &#82 &#79 &#71 &#82 &#65 &#77 &#77 &#73 &#78 &#71

ISO 10646 (1991-1993) (references)

004C 0049 0054 0045 0052 0041 0054 0045      0050 0052 004F 0047 0052 0041 004D 004D 0049 004E 0047

Encryption (beginner's substitution cypher): (references)

464354395235543925052494152354747434841

Top     



INDEX

1. Crosswords
2. Usage: Commercial
3. Expressions: Internet
4. Orthography
5. Bibliography


  

Copyright © Philip M. Parker, INSEAD. Terms of Use.