Live data from Hacker News

What is “literate programming”? (2024)

pqnelson.github.io

1–10 of 57 posts

Re: What is “literate programming”? (2024)

#2
To me the definition of literate programming is much less interesting than the spirit: for complicated logic / parts of code, I try to take the reader through the whole top-down plan / approach, as if it’s a story I’m writing to my colleagues about what’s going on and why. In those parts of code I can easily have 10 times as much lines of comments than code, but it’s important to use it sparingly: people tend to start to ignore comments if they’re low value. But it’s much more effective to have good comments than external documentation, as external documentation has a tendency to go out sync with the code.

As with most things, don’t be dogmatic.

Re: What is “literate programming”? (2024)

#3
The examples are definitely acknowledgement worthy.

I imagine the biggest hurdle on the path towards adopting this is writing down clear, readable prose using highly technical language. And naming things. Using ambiguous human language to describe a complex algorithm without causing a conflict in a big team.

Re: What is “literate programming”? (2024)

#4
This essay seems to be missing the main primary references for literate programming:

https://www.cs.tufts.edu/~nr/cs257/archive/literate-programm...

https://www-cs-faculty.stanford.edu/~knuth/lp.html

Knuths intention seems clear enough in his own writing:

Literate programming is a methodology that combines a programming language with a documentation language, thereby making programs more robust, more portable, more easily maintained, and arguably more fun to write than programs that are written only in a high-level language. The main idea is to treat a program as a piece of literature, addressed to human beings rather than to a computer.

and

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 human beings what we want a computer to do.

Re: What is “literate programming”? (2024)

#6
Couple things that helped me understand literate programming:

- A literate program has code and documentation interleaved in one file.

- Weaving means extracting documentation and turning it into e.g. a pdf.

- Tangling means extracting code in a form that is understandable to a compiler.

A crucial thing to actually make this paradigm useful is the ability to change around the order of your code snippets, i.e. not letting the compiler dictate order. This enables you to code top-down/bottom-up how ever you see fit, like the article mentioned. My guess on why people soured on literate programming is that their first introduction involved using tools that didn't have this ability (e.g. jupyter notebooks). Also, you usually lose a lot of IDE features: no go-to-definition, bad auto-complete, etc.

IMO, the best tool that qualifies for proper literate programming is probably org-mode with org-babel. It's programming language agnostic, supports syntax highlighting and noWEB for changing around order. Of course it requires getting into the Emacs ecosystem, so it's destined to stay obscure.

Re: What is “literate programming”? (2024)

#7
Maybe it will be unpopular opinion but if your idea has to be explained after 50 years in a blog post maybe it was not that good after all. Or maybe idea was good but state of the tools and culture of your field is not best place to implement it, like the blog post ask: what tool you would use for literate programming? Or you need to write a tool for literate programming first? For me it sounds bit like runnable python notebook, which is great for DevOps stuff but not really for developing financial system. And I do not want to start about lack of tests as author states.

Re: What is “literate programming”? (2024)

#8
Maybe I am weird, but I would like to see/program in a formal, yet fuzzy/modal language, which could serve as a metalanguage that describes (documents) the program. This metalanguage must have some kind of constructs to describe unknown things, or things that are deliberately simplified in favor of exposition. So basically eschew natural language completely in favor of fully formalized description, that could be manipulated programmatically.

However, I don't know what this metalanguage should be. I don't know how to translate typical comments (or a literate program) into some sort of formal language. I think we have a gap in philosophy (epistemology).

Re: What is “literate programming”? (2024)

#9

Couple things that helped me understand literate programming: - A literate program has code and documentation interleaved in one file. - Weaving means extracting documentation and turning it into e.g. a pdf. - Tangling means extracting code in a form that is understandable to a compiler. A crucial thing to actually make this paradigm useful is the ability to change around the order of your code snippets, i.e. not let…

I’d guess that tools like Doxygen and Apple docc are probably the most obvious examples of documentation extraction.

I’ve written code for many years, with Doxygen/Jazzy/docc in mind (still do[0]). I feel that it’s a big help.

[0] https://littlegreenviper.com/leaving-a-legacy/

Re: What is “literate programming”? (2024)

#10

To me the definition of literate programming is much less interesting than the spirit: for complicated logic / parts of code, I try to take the reader through the whole top-down plan / approach, as if it’s a story I’m writing to my colleagues about what’s going on and why. In those parts of code I can easily have 10 times as much lines of comments than code, but it’s important to use it sparingly: people tend to star…

> As with most things, don’t be dogmatic.

It depends. If you want to learn faster, you should be dogmatic: "In der Beschränkung zeigt sich erst der Meister." If you want to become a better programmer, please do set extra challenges (fe pure lazy functional progamming only, pure literate programming, ...)

Post reply on HN