42 ms·
Literate programming: Two beefs with the classic version (2014)
- joshmarinacci 11y agoThe problem of literate programming, as with many of these systems, is that they presuppose a text file on disk with a parsing order. Fundamentally code is a graph, we've just badly flattened it to a poor on disk format. If we could work, and annotate, at the graph level we'd see far more literate programming.
- DominikD 11y agoThat's true, code is rarely linear. But the whole idea of encapsulation, separation of concerns and many, many other practices is to increase locality of a code. In that sense a well written and structured code has local, mostly linear systems that you can analyze in isolation to get insight into the larger system. With this in mind it doesn't matter that the overarching structure is much more complex. Translation unit you're analyzing is (or should) be mostly human-parsable in a linear fashion. What I found eye-opening in this article is that it challenged my concept of well structured code file. I was like "what?! this is blasphemy!" from the very beginning but at the end I was like "huh, I finally understand why sometimes #define's feel better in the center of a file than they feel at the top"[1]. It's rare for a blog entry to stir me like this. :) [1] amongst other things that came though my head
- akkartik 11y agoThanks for the kind words!
- MichaelGG 11y agoThis is why programming languages that support nesting really help in some scenarios. It's great to be able to write functions inside functions, with or without captured variables/bindings. (I know a tree isn't all graphs, but it works well for many scenarios.) When I start on a new program in F#, I usually just start with one main function and keep typing straight on down. When I want to re-organize it into a module, it's usually nearly as easy as writing "module" at the top. Without this, one is encouraged to either not abstract properly as the overhead and context for a new top-level function is too much, or you end up with free-floating functions that don't belong there and only have a single caller.
- lisper 11y ago#includes are a totally broken idea. They are the canonical violation of the DRY (Don't Repeat Yourself) principle. With #includes, whenever you want to make a change in the signature of a C function you have to do it in two places. The only reason we have them at all is because early C compilers were one-pass compilers, and so they needed to have declarations spoon-fed to them in the right order so that they could run in the 64k or so of RAM that was available on the PDP-8. There is no good reason to have includes today except that the C legacy is so strong and the idea is so deeply entrenched in people's minds and in the structure of C that they are nearly impossible to get rid of.
- aab0 11y agoIsn't the problem here imports in general? Imagine these examples written in a literate Haskell file .lhs: 'Let us discuss graph search... > import Control.Monad'
- akkartik 11y agoI think lisper was raising a tangential but still valid point. Haskell imports don't suffer from the problem he was pointing out; we only see the function type in one place. It's not the fault of Haskell imports that literate programs put them first.
- dllthomas 11y agoNote that in Knuth's formulation of literate programming, you could freely reorder the program source. So those imports needn't be at the start of the literate program - they could be off in a parenthetical appendix.
- Ericson2314 11y agoAh, finally a break from pure Knuth worship for something objective. http://unisonweb.org/ http://unisonweb.org/ doesn't espouse the term"literate programming" itself, but its ideals are comparable. Oh, and, no imports whatsoever :).
- PaulHoule 11y agoLately I have been working on "hyper hypertext" which involves mashing up code with supporting documentation, making the most of things like Javadoc, etc.
- fibo 11y agoI disagree with the Author: literate programming is Great but it is true that gives a better result For small codebases. I have few tiny projects that are just a README.md which contains code and docs, and I am really glad about this Solution I called KISS Literate Programming: as an example, see http://g14n.info/bb-clone/ http://g14n.info/bb-clone/
- e12e 11y agoI found this talk about re-structuring and bringing back to life a 1.2 MLOC lisp codebase with classical LP interesting (it's a bit meandering, but INHO well worth a watch): "Literate Programming in the Large": https://www.youtube.com/watch?v=Av0PQDVTP4A https://www.youtube.com/watch?v=Av0PQDVTP4A The reorganization is still ongoing, as can been seen at: http://www.axiom-developer.org/axiom-website/currentstate.html http://www.axiom-developer.org/axiom-website/currentstate.ht...
- johnwatson11218 11y agoAnytime I hear about literate programming I think about how mathematicians worked for centuries to encode math symbolically. If you look at the ancient math texts it was all word problems and it was just awful. One of the coolest things about math is how the symbolic representation of the problem allows your mind to work out solutions with less effort. I think the future of programming looks more like math than english.
- dllthomas 11y agoLet's look at some actual math. The first article from the most recent issue of the first journal listed on the AMS page is here: http://www.ams.org/journals/ecgd/2016-20-01/S1088-4173-2016-00288-5/S1088-4173-2016-00288-5.pdf http://www.ams.org/journals/ecgd/2016-20-01/S1088-4173-2016-... To me that looks like quite a bit of English, organized for humans. It is true that there are also quite a few symbols, but I contend it looks a whole lot more like the CWEB implementation of wc than it does like the C implementation.