by guitarbill · 9y ago · 0 comments
From what I've seen, literate programming is great in theory and worse than useless in practice. It's so far away from reality. I have had the misfortune of working on a FunnelWeb codebase, and it was one of the most incomprehensible codebases I've ever seen.
Preprocessing the code is an awful step in any language. Somehow, the "not documentation" still goes out of date. There are several other problems, explained at [0] better than I can in a comment.
Specifically about this project: While I enjoy writing blogs in markdown because of its constraints, reStructuredText (reST) is more powerful/expressive (by design). Because you can easily express semantics/relationships, the resulting links in the generated documentation make the "web" of source code easier to navigate - something Knuth was trying to do with literate programming.
https://github.com/jameysharp/corrode/blob/master/src/Langua...
[0] https://stackoverflow.com/questions/16869050/is-literate-pro...
Literate programming goes in the opposite direction, and I don't think that's necessarily good, though it has it's use cases. I think data science with Jupyter notebooks are a great display of when it's good (and that's likely the best / most used form of literate programming out there), because in data science a lot of what you need to justify is the "why" a calculation is done the way it's done. Pretty graphs inline are just a bonus.
For ordinary code though? Comments are a fallback for complicated bits, but I feel like they shouldn't be the norm. I want people to write code that doesn't need hand holding just to understand.
If your end goal is to produce some kind of largely static artifact then literate programming is fine. For everyday code where you iterate and refactor all the time, literate techniques have all the downsides of prolific comments.
I've found it really useful for a big Django project, when I add some functionality, the definition of the models, views, dependencies and URL references are all adjacent in a nicely indicated section and subsections. Navigating around it in a PDF reader has been more pleasent than scrolling up and down code, and hunting for the appropriate file, as I would often find myself doing in Eclipse.
I'm also able to put output of the tests into the doc, and a full set of installation instructions from a fresh machine, and usage instructions, in the same doc with pointers to the appropriate code chunk.
Much of this can be achieved in various other ways. But the actual result is that I've been much happier in my last few literate projects, than I was in the ones before that.
Finally, I've also noticed that I don't have the encroaching feeling of my current project getting a bit big and unwieldy even though this is easily the most complicated thing I've ever done.
But according to Knuth, literate programming is about more than online code, it also includes the whole web-o'-macros thing.
> I'm also able to put output of the tests into the doc, and a full set of installation instructions from a fresh machine, and usage instructions, in the same doc with pointers to the appropriate code chunk.
Python has ways of doing this, and all of this just feels like overloading a document. Repos exist for this, and work fine keeping everything together.
Funny you ask this, I ran across a @raganwald post mentioning a great example of ^literate programming^ (mixing code and documentation), "Literate CoffeeScript" [0]. You can read about how CoffeeScript does this at http://coffeescript.org
[0] blog post: http://raganwald.com/2013/03/27/literate-coffeescript.coffee...
[1] raw text: https://raw.githubusercontent.com/raganwald/raganwald.github...