Literate Programming

Created: by Pradeep Gowda Updated: Oct 06, 2018 Tagged: 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 humans what we want the computer to do. – Donald E. Knuth, Literate Programming, 1984

Examples of literate programming

  • ulix a literate, teaching operating system.
  • knitr Elegant, flexible and fast dynamic report generation with R
  • stich – is a small python library for writing reproducible reports in markdown. It’s heavily inspired by (read: a python clone of) knitr and RMarkdown.
  • the entire source of Ferret programming language as an emacs org file.


Literate – A modern literate programming system written in D

brew tap zyedidia/literate
brew install --HEAD zyedidia/literate/literate

In addition to those of CWEB:

  • Markdown based – very easy to read and write Literate source.
  • Generates readable and commented code in the target language (the generated code is usable by others)
  • Reports syntax errors back from the compiler to the right line in the literate source
  • Supports any language including syntax highlighting and pretty printing in HTML
  • Compatible with Vim (literate.vim)
  • Highly customizable (you can add your own HTML or CSS)
  • Runs fast – wc.lit compiled for me in 7ms for both code and HTML output
  • Supports TeX equations with $ notation.

Inspired from CWEB:

  • Automatically generates hyperlinks between code sections
  • Formatted output similar to CWEB

I wrote lua4py page using Literate.