# Literate Programming

- Page: https://shared.btbytes.com/p/literate
- Date: 2018-10-06
- Tags: 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](http://ulixos.org/) a literate, teaching operating system.
- [knitr](http://yihui.name/knitr/) Elegant, flexible and fast dynamic report generation with R
- [stich](https://pystitch.github.io/) -- is a small python library for writing reproducible reports in markdown. It's heavily inspired by (read: a python clone of) knitr and RMarkdown.
- [ferret.org](https://github.com/nakkaya/ferret/blob/master/ferret.org) the entire source of Ferret programming language as an emacs org file.


## Tools

[Literate](https://github.com/zyedidia/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](https://github.com/zyedidia/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](https://www.btbytes.com/lua4py.html) page using Literate.

---

See also the [Nimib](https://pietroppeter.github.io/nimib/index.html) project by Nim programmers.
