5 ms·
Every few years, I contemplate the idea of trying out literate programming. I get that notebooks have continued to trends of "mixing prose and code" to great su
by phtrivier 3y ago
Every few years, I contemplate the idea of trying out literate programming. I get that notebooks have continued to trends of "mixing prose and code" to great success ; however, I really wonder how the "out of order programming" works out in practice.
Sadly, I never managed to go passed the "my editor cannot show syntax highlighting for a mix of languages." :/
- iib 3y agoThis is doable in Emacs, using org-mode and org-babel.
- phtrivier 3y agoYou're right, I should have mentioned org-babel as the closest thing to something that would work for me. However, as soon as I start using noweb syntax for "out of order" programming, I stumble into long standing bugs (references are not always found, links in the tangled code are broken, detangling does not work, etc...)
- wolfgang42 3y agoNot sure what editor you use, but most syntax highlighters these days can mix languages: you see this e.g. in HTML <style> tags and Markdown fenced code blocks. As for 'out of order programming', I think that TANGLE-style reordering is a lot less important with modern programming languages: they don't do one-pass compilation and so can deal with forward references. Note that most of the cross-references in Knuth's program could be replaced with function calls or constant names, rather than the semiautomatic inlining that WEB performs. I've had some success in writing literate programs in a Markdown file, with a small script to extract the code blocks into a file for execution. This seems to work fine, at least on a small scale, and is very easy to implement and then extend if needed. Edit: and by “small script” I mean: import sys code = False for line in sys.stdin.read().splitlines(): if line == '```': code = False # End block if code: print(line) # Only output block contents if line == '```md': code = True # Start block It also seems worth noting that you can get much the same result just by writing a lot of comments; this technique is mainly useful when you also want more formatting than can be reasonably squeezed into plain text. /edit