frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Literate programming tool for any language

https://github.com/zyedidia/Literate
59•LorenDB•5h ago

Comments

tony_cannistra•4h ago
Been around for a long time indeed. I first learned literate programming in college at Tufts, from Norman Ramsey. He wrote noweb[1], an early implementation of Knuth's ideas.

[1]: https://en.wikipedia.org/wiki/Noweb

onair4you•3h ago
Oh you beat me to it!
make3•4h ago
I feel like being able to import notebooks like `import notebook_name` and run jupyter notebooks (more easily) like `python notebook.ipynb` and the analogue in different languages would already get us 99% of the way there
jedimastert•3h ago
There's a pretty direct line between the concept of notebooks and literate programming.
audiodude•3h ago
Is there any intrinsic reason why Jupyter Notebooks can't be imported? You don't know which code blocks to run?
make3•1m ago
not really, you can just run the blocks one by one like `nbconvert --to script` does. Looks like https://pypi.org/project/importnb/ exists
mapcars•4h ago
Literate programming is an intriguing concept, but its hard to compete with modern IDEs. Having build system is good, but can you get proper syntax highlight for the code segments? Or goto-symbol, real-time typechecking?

I feel like it needs its own IDE, because now apart from the coding abstractions you also have named snippets.

corysama•3h ago
Code-as-a-Database is something lots of people would like to have, but not much effort has been put into implementation since... Smalltalk? Could still be a pile of loose text files with markup. Like how https://obsidian.md/ is an informal graph database of loose markdown files.
ModernMech•3h ago
There's an active research community based around this very idea: https://liveprog.org, also https://www.hytradboi.com
codebje•2h ago
I write a bit of literate Haskell, sometimes. It's one of the most well supported literate programming systems out there: the compiler supports it, the language server supports it, using VSCode as an "IDE" means full support for all the things you mentioned. Haskell code formatters don't seem to support literate Haskell, though, and GitHub Copilot, at least, gets confused between prose and code (but that's fine, if I'm taking the time to make my code extra readable and understandable the last thing I want is for an AI to get involved).

Maybe a tool like the one presented here could work as a language server proxy to the underlying language's server. The presence of literate text alone doesn't seem to be the main issue, it's getting the code portions parsed, checked, and annotated with references that matters.

taeric•2h ago
I mean... somewhat yes to all of those? Emacs can even do most of what you are asking for. When I export an org buffer, it even has the syntax highlighting in the html that I was looking at. :D

Obviously, the type checking will be a bit more limited for code snippets you haven't finished. But especially for image based environments, it should have everything that you have in the image just fine.

CWEB, which is the one that Knuth prefers, even supports step debugging. Has supported it for decades, at this point.

WillAdams•2h ago
This is why I use LuaLaTeX for this:

https://github.com/WillAdams/gcodepreview/blob/main/literati...

which allows me to have an ordinary .tex file:

https://github.com/WillAdams/gcodepreview/blob/main/gcodepre...

which outputs multiple .py and .scad files and generates a .pdf with nice listings-based code blocks, ToC, index, hyperlinks, &c.:

https://github.com/WillAdams/gcodepreview/blob/main/gcodepre...

The notable downsides are that the .sty and .tex files have to be customized for the filenames which one can output, and I haven't been able to get auto-line numbering working between code blocks, so one has to manually manage the counters.

hongbo_zhang•1h ago
Yes, I think this is the missing part. You may have a look at MoonBit(https://www.moonbitlang.com/blog/moonbit-markdown) which has the full IDE support in the markdown editing
svieira•4h ago
The fact that the actual implementation is in `lit` too is really helpful - getting to see how one would actually use this on a larger program does make it much more intriguing than the simple examples (and much more approachable than TeX itself).

https://github.com/zyedidia/Literate/tree/master/lit

groos•3h ago
Ignore the naysayers here. Good job!
jostylr•3h ago
I've been wondering if AI coding agent world makes literate programming valuable again. I got into it with JavaScript being a mess prior to the modern changes. Needed a lot of workarounds. Then they improved the language and it felt like coding could be efficient with them. But if the programmer switched from coding to reviewing, maybe it would be good to be able to have various snippets, with an explanation preceding it and then verifying it. Haven't tried it yet. But I do wonder.
thyrsus•3h ago
If your colleagues just don't feel the benefit of the extra .lit file, is there a way to pull their changes to the derived files into your own .lit files and to keep the .lit files in a parallel version control repo or branch?
taeric•2h ago
Sorta? Noweb and org mode's support of it, at least, has a "detangle" and it worked surprisingly well last time I tried it. You can't edit the comments it puts in the source, for obvious reasons. And I'm sure it has trouble if you tried to get too fancy. But it did allow me to edit the generated source directly and pull those edits back into my literate source. I imagine if this was something people were more often doing, you could make it more reliable, even.
BeetleB•57m ago
Leo probably has the best implementation of bringing in others changes into your literate project.
onair4you•3h ago
https://en.m.wikipedia.org/wiki/Noweb
w10-1•3h ago
This doesn't seem to provide any context for literate programming, or the core literate operations?

cf leo editor for literate programming in python [0]

Yes, markdown has code blocks, and notebooks have embedded code in documentation since Mathematica in the 1980's. It is possible to get IDE support in such blocks.

But for literate programming, weaving/tangling sources is needed to escape the file structure, particularly when the build system imposes its own logic, and sometimes one needs to navigate into the code. Leo shows how complicated the semantics of weaving can get.

Eclipse as an IDE was great because their editor component made it easy to manage the trick of one editor for many sources, and their markers provided landmarks for cross-source navigation and summaries.

[0] https://leo-editor.github.io/leo-editor

nico•3h ago
Great concept and very relevant today[1]

It’s interesting that using LLMs is making very explicit that “someone” needs to read the code and understand it. So having good comments and making code readable is great both for AI and humans

1: “Writing documentation for AI: best practices” https://news.ycombinator.com/item?id=44311217

amanwithnoplan•2h ago
Another interesting implementation of literate programming with _bidirectional sync_ between documentation and source code is Entangled (https://entangled.github.io/). This allows you to use all your normal tooling on the normal source code files, and the changes are reflected back to your Markdown documentation files.
seanwilson•2h ago
Maybe I'm missing something but how often is the English in literate programming repeating what's already written in the code? Does it work for large projects where it's often hard to explain all the parts in a linear way in the style of an essay?

I avoid code comments where I can because English is way less precise than code, it's an extra chore to keep the comments and code in sync, and when the comments and code inevitably get out of sync it's confusing which one is the source of truth. Does literate programming sidestep this somehow? Or have benefits that outweigh this?

juliangmp•2h ago
I'm not sure who first coined this idea or put it in a book or where I've read it, but for code comments I generally like the "explain why, not what" philosophy. The "what" is answered by the code itself and should be easy enough to comprehend if your design is simple and your names meaningful. The "why" is much more important. Why does this parser check for some magic numbers at this specific offset and change some parameters if it finds them? If you don't explain that its because of e.g. compatibility with some legacy format, its gonna be a mystery to the reader.
taeric•2h ago
I think this certainly happens a fair bit. Not at all uncommon to have a section that largely says what is going to happen next, which, fair that what is going to happen is what happens.

I think where it shines, is where it helps you break the code up, without having to break it up in a way that makes sense for the computer. Show an outline, but then drill into a section. The overall function can then be kept as a single unit, and you can sort of punt on sub sections. I tried this just recently in https://taeric.github.io/many_sums.html. I don't know that I succeeded, necessarily. Indeed, I think I probably should have broken things into more sections. That said, I did find that this helped me write the code more than I expected it to. (I also was very surprised at how effective the goto style of thinking was... Much to my chagrin.)

I will have to look again at some of the code I've read this way.

To directly answer the question of if it helped keep the documentation in sync, as it were, that is tough. I think it helps keep the code in a section directly related to the documentation for that section. All too often, the majority of code around something is not related to what you were wanting to do. Even the general use of common code constructs gets in the way of reading what you were doing. Literate programming seems the best way I have seen to give the narrative the ability to say "here is the outline necessary for a function" and then "this particular code is to do ..." Obviously, though, it is no panacea.

seanwilson•34m ago
> I tried this just recently in https://taeric.github.io/many_sums.html.

Literate programming seems fine for heavily algorithmic stuff when there's a lot of explaining to do compared to the amount of code and the code is linear, but I was more thinking about how it works for common web apps where it's lots of mundane code that criss-crosses between files.

WillAdams•27m ago
My current project for a while was in a state where it was necessary to keep code in 3 separate files:

- gcodepreview.py (gcpy) --- the Python functions and variables

- pygcodepreview.scad (pyscad) --- the Python functions wrapped in OpenSCAD

- gcodepreview.scad (gcpscad) --- OpenSCAD modules and variables

as explained in: https://github.com/WillAdams/gcodepreview/blob/main/gcodepre... and it worked quite well (far better than the tiled set of three text editor windows which I was using at first) and I find the ability to sequence the code for the separate files in a single master file very helpful.

billfruit•1h ago
I prefer to add huge amounts of comments, explaining in as much detail as I can, sometimes it will be a mini-essay in there. I write most of it before I write the code. It helps me formulate the code better. Later it serves as explanatory text.

Usually the problem with comments is that there is too less of it.

seanwilson•13m ago
> Usually the problem with comments is that there is too less of it.

I've worked in a few code bases where many of the comments could be removed by using better function names, better variables names, and breaking complex conditionals into named subexpressions/variables.

And there was a fair chance comments were misleading too or are noise that don't add anything e.g. `/* send the record for team A */ teamB.send(...`, `/* if not logged in and on home page */ if (auth.user && router.name === 'home') ...`, `/* connect to database */ db.connect()`. I'd much rather comments were used as last resort as they're imprecise, can be bandaids for code that's hard to read, and they get out of sync with the code.

A blocks of comments to explain the high-level details of complex/important code, or comments to explain the why or gotchas behind non-obvious code are useful though.

monkeyelite•48m ago
The primary benefit of literate programming is being able to change the order of presentation.

But even then my experience doesn’t match yours. So you have some code. Who decided it would be that way? Do you have a picture of how it should look? Can you share a link to where you got this information? What problem led you do to this non-obvious thing?

JAHDIEL1•2h ago
Español
bilalq•2h ago
I actually did some small hobby projects using Literate Coffeescript a long time ago. Looking at the source code today, and I can't help but feel like the proponents of literate programming were really onto something. I'm coming back a decade later, but I can easily see what's going on and why at a glance. Compared to many other projects that I've written in the past without documentation, it's a completely different vibe. The Gulpfile in particular is such a treat to read.

Yeah, it can look a bit repetitive if the code is already clear, but the context of why a thing is being done is still valuable. In the modern era with LLM tools, I'm sure it could be even more powerful.

ai-christianson•33m ago
> Yeah, it can look a bit repetitive if the code is already clear, but the context of why a thing is being done is still valuable. In the modern era with LLM tools, I'm sure it could be even more powerful.

Is that because of literate programming, or is that because practicing literate programming made you focus more on writing high quality code and docs?

txgvnn•2h ago
If you are interested with Literate programming, you should try Emacs. Some packages are org-mode, eev and even elisp are best for literate programming. Example https://www.youtube.com/watch?v=dljNabciEGg
smitty1e•1h ago
Org-babel[1]:

"Literate programming (LP) offers 2 classical operations:

    Tangle: Extract the source code blocks and generate real working code files for further compilation or execution, eventually outside of Emacs.

    Weave: Export the whole Org file as literate, human-readable documentation (generally in HTML or LaTeX)."


[1] https://org-babel.readthedocs.io/en/latest/

It's time for Stanford to see what they got

https://v0-youtube-video-parser-dusky.vercel.app/
1•jinxin238357•5m ago•0 comments

Top Internal Developer Platforms Compared for 2025

https://wso2.com/library/blogs/top-ten-internal-developer-platforms-compared-2025/
1•kavishkafdo•7m ago•1 comments

Show HN: Tool to Automatically Create Organized Commits for PRs

https://github.com/edverma/git-smart-squash
1•edverma2•20m ago•0 comments

China's $5T Industrial Policy Weapon: State-Backed Finance

https://www.governance.fyi/p/chinas-5-trillion-industrial-policy
4•daveland•27m ago•1 comments

SoftwareFPU

https://apple.fandom.com/wiki/SoftwareFPU
1•thomassmith65•27m ago•0 comments

I Hate Conventional Commits

https://beyermatthias.de/i-hate-conventional-commits
1•kaladin-jasnah•32m ago•0 comments

Local High School Radio Station KVHS to go dark at the end of the month

https://sites.google.com/view/theendofkvhs/home
2•sandboxdev•33m ago•1 comments

Claude Code, not only for Devs

https://hackertarget.com/claude-code-more-than-coding/
3•the_wanderer•34m ago•0 comments

Show HN: Ts-SSH – SSH over Tailscale without running the daemon

https://github.com/derekg/ts-ssh
1•i8code•40m ago•0 comments

A developer's guide to AI protocols

https://www.infoworld.com/article/4007686/a-developers-guide-to-ai-protocols-mcp-a2a-and-acp.html
1•akanapuli•42m ago•0 comments

PSA: Codex crossed 350K GitHub PRs merged

https://twitter.com/anjneymidha/status/1935865723328590229
1•anjneymidha•43m ago•0 comments

Zig and Rust

https://matklad.github.io/2023/03/26/zig-and-rust.html
1•Bogdanp•43m ago•0 comments

Show HN: What would you do if you were given Half Billion Dollar?

https://hbdq.ddgr3.com/
1•jujumilk3•44m ago•3 comments

Learning-based density-equalizing map

https://arxiv.org/abs/2506.10027
1•PaulHoule•48m ago•0 comments

Crystal: An IVE: Integrated Vibe Environment

https://github.com/stravu/crystal
1•handfuloflight•49m ago•1 comments

Show HN: Consciousness Is Synergistic Information

https://zenodo.org/records/15696326
2•NetRunnerSu•50m ago•1 comments

Satanic Text Generator

https://lingojam.com/SatanicTextGenerator
1•some-guy•50m ago•2 comments

Encounters with Reality on Christine Rosen's the Extinction of Experience

https://thepointmag.com/criticism/encounters-with-reality/
1•prismatic•50m ago•0 comments

Bela Upgrades Embedded DSP Platforms with PocketBeagle 2 Support and New Web IDE

https://linuxgizmos.com/bela-upgrades-embedded-dsp-platforms-with-pocketbeagle-2-support-and-new-web-ide/
2•eddiemorphling•51m ago•0 comments

Getopt() but Smaller

https://dotat.at/@/2024-11-06-getopt.html
1•signa11•55m ago•0 comments

Financial News Aggregator

https://www.financial-news.space/
1•nonplayercaesar•1h ago•0 comments

Is an AI Catastrophe Inevitable? [video]

https://www.youtube.com/watch?v=86k8N4YsA7c
1•trinsic2•1h ago•1 comments

A Retro YouTuber Wants to Take over Commodore. Yes, He's Serious

https://tedium.co/2025/06/19/peri-fractic-retro-recipes-commodore-profile/
4•shortformblog•1h ago•6 comments

What the Kite Saw: A Story of Collective Resistance to War

https://childrensbookforall.org/past-readings/20250413
1•chbkall•1h ago•0 comments

Intel NPU Accelerator Driver Readies "Turbo Mode" for Better Performance

https://www.phoronix.com/news/Intel-NPU-Turbo-Mode-Linux-6.17
2•gametorch•1h ago•1 comments

Should I block the Semrush bot?

https://old.reddit.com/r/SEMrush/comments/1lfst79/should_i_block_the_semrush_bot/
1•gametorch•1h ago•1 comments

Apple Created a Custom iPhone Camera for F1

https://www.wired.com/story/apple-created-a-custom-iphone-camera-for-f1/
2•tatersolid•1h ago•0 comments

Engineering log: deploying new pyrolysis hardware

https://charmindustrial.com/blog/the-bighorn-journey
1•n2parko•1h ago•0 comments

America's ideal woman got jacked

https://www.vox.com/culture/417063/women-muscles-strength-weight-training-casey-johnston-amy-larocca-bonnie-tsui
1•mooreds•1h ago•1 comments

What explains the liberal-conservative happiness gap?

https://www.natesilver.net/p/what-explains-the-liberal-conservative
9•ivewonyoung•1h ago•7 comments