r/ProgrammingLanguages • u/othd139 • Apr 08 '26
Requesting criticism I'm Writing An eBook Teaching How To Write A Compiler
I've been writing an eBook on how to write a compiler using my custom backend I posted here a couple of weeks ago Libchibi (which I've made quite a few changes to as the process of writing this book has revealed flaws and bugs). I'm a fair way from done but I've reached an important milestone and I successfully wrote a pendulum simulation using raylib to render it in the language I've been developing in the book. I'd love some feedback as to the tone, teaching style, density, depth etc... if anyone feels like having a look (although I get that it's kinda long for something incomplete so I'm not expecting much). In any case the language I've been writing for it is kinda cool and at the point of being genuinely usable (although a ways from being preferable to anything out there already for serious use). Anyway, here's the repo: https://github.com/othd06/Write-Your-First-Compiler-With-Libchibi
Edit: It's just occurred to me I didn't really describe what I was going for with the eBook. I was quite inspired by Jack Crenshaw's Let's Build A Compiler if any of you are aware of that 80s/90s classic so I wanted to keep the practical, conversational tone of that but I wanted to introduce tokenisation and grammar much earlier so that I don't get stuck with a lot of the downsides that book had. So it's quite practical and building and giving enough theory to be grounded and know where you are but quickly into actually building something and seeing results.
Edit 2: Thank you so much to the people who have given feedback and criticism so far. I've pushed an update to my repo for chapters 0 through 6 so far implementing a lot of what was said and I think it is a significant improvement so thank you so much. I will obviously continue to edit and refactor the rest until the whole book (so far!) is up to the standard everyone here has helped to get the start now up to.
18
u/thmprover Apr 09 '26
I just gave it a cursory read, but I have some feedback.
Who is your audience? What do you assume on the part of the reader? What's your "mission statement" for this book?
It's clear you are competent and knowledgeable. I am not sure who your audience is, so I can't give much feedback.
I notice you don't seem to use sections to cluster things together (except in chapter 7), which can make it harder for someone to learn. If I were completely ignorant, it's hard for me to say, "OK, I get [this section] but [that section] confuses me"...because there are no sections.
A heuristic copy editors tend to use is if chapters are wildly different in lengths, then you should examine how you are organizing your material. And your chapters are wildly different in lengths, so it may be a good thing to ponder. (The same heuristic works for sections: if sections are wildly different lengths, then that could be a sign that it could be organized better.)
The prose is good, but it also feels...well, in the later chapters, more like a code dump with some prose sprinkled in between. Which is a pity, because your prose is good.
Also, a good rule of thumb is to limit yourself to a maximum of 25 lines of code per "chunk" of code.
"One weird trick" that helps writing books like this: make the code as simple as possible, even if it comes at the cost of writing code that shouldn't be in production. The code should illustrate the important relevant ideas, not get bogged down with the irrelevant ideas.
4
u/[deleted] Apr 09 '26
[removed] — view removed comment