2013/Literate Programming for the 21st Century
Knuth advocated writing programs for people, not computers. How does crafting code with literate programming play with quick iterative development? Example heavy session using org-mode’s Babel project and progrmming languages with succinct syntax, like Scala and Clojure.
Speaker: Howard Abrams
Return to this session's details
Notes by Colin Dabritz:
In 1980s Donald Knuth - "Let us change our traditional attitude to the construction of programs. Instead of…" "The programmer's task is to state [the] parts and relationships, in whatever order is best for human comprehension not in some rigidly determined.. "Literate Programming"
"computer programming is an art…"
Idea Take a document, a file, write it out Some kind of macro system to tease out two forms, one code for the computer, the other documentation for people. Code for the computer - Tangling Writing for humans - Weaving "macro system"
Words at the top Section code end of code block Code blocks are named
(slide examples) called "the web" because no one was using the term at the time… 1984 paper literate programming, into book "literate programming"
Antithesis Doug Mcllory - A wise engineering solution would produce - or better, exploit - reusable parts
rebuttal - series of unix commands with pipes tr -cs A-Za-z '\n' | etc etc
It's funny, it's reusable [and misses knuths point] -Po Petz
Doug Mcllroy Code re-use
Donald Knuth Better thinking through better tools
Influences: Javadoc system Docco iPython notebook Haskell Embraced by Cryptic Languages
iPython notebook example
(looks a lot like wards federated wiki with markup for behaviors?)
Synthesis Clearly the need is there, but…
What is needed? Good text processing and programming Need to ID and separate code from doc code block evaluation support (a step above a REPL) Link and reference code block snippets use evaluated code output render both code and documentation
One tool that kinda goes and embraces this completely, came from a very different place Carsten Dominik - "in the third millennium does it still make sense to work with text files? Text files are the only truly portable format for files. The data will never get lost."
back to tangling/weaving, but one more thing. REPL connect to interpreter, you can farm off the code to get feedback, and can go from language to language. example alternating between prose and code - lists and tables and textual data in text, can feed into code. Code can feed back to next text results in document. Knuth originally interconnected code. This system can interconnect code and data in a literate way.
Toolbox: babel, org-mode, Emacs (language modes, Graphviz/PlantUML, REPL Connectors)
Example org mode file, in Emacs Not a lot here Outlining, showing levels of outlining Hyperlinks Mode to text mode - Just text, grep, find etc. "I can kind of interconnect everything, wiki style" Table formatting, adjusting text columns Spreadsheet behaviors Render and display results e.g Graphvis [Workflow? e.g. render to webpage] interesting part - source code code example (clojure, js) can farm off code examples into special language specific mode, (like a mini IDE) Hit a key, farms off code to interpreter, data comes back into next section in plain text. Orgmode recognizes list of lists as a table and reformats (can turn off to just closure code, e.g. list of lists) Provides a language translation layer Shell script example lsof | grep LISTEN | grep IPv4 Results show as table based on the spacing each code section can specify variables for other code block results, or text you type in.
fun experiment, ran process and got a bunch of times. feed data to second script split data and put back total results
examples from actual coding source code finder with different languages in the same file verifying A/B testing experiments in Python different hashing algorithms
Possible Uses Learning a new language or tech Combining code with tests [annotations?] Better REPL for non-interactive languages Easier to brain-storm over complex analysis problems require multiple languages embedded UML or other diagrams Describe complex code: -regular expressions -odd inheritance trees -SQL and ORM
[like pipes with more tools]
[How does sharing text files, or multi editing work here?]
Running destructive commands? Only on demand, so need to handle that.
Editor? Emacs for this, challenge to port to VIM. (generally don't recommend switching editors)
Results saved? Yes, saved in document itself. (until rerun)
Assuming code wants to be available.