The author says it took about 6 months to thoroughly go through the book and examples. This is really useful in setting expectations.
I got through all chapters in around 1.5 months, spending 50-60 hours[1]. I'd do solid 4-5 hour blocks on Saturdays and Sundays when I was most into it. I'm following teachyourselfcs.com[2], so I'm hoping to solidify the concepts the book intro'd by reimplementing the bytecode interpeter in Rust (rlox) and following Alex Aiken's lectures online. OP appears to have reimplemented Lox in Golang (glox) for reinforcement.…
Crafting Interpreters: A Review
61–70 of 155 posts
Re: Crafting Interpreters: A Review
#62It's definitely well-written and you can feel the love and care that went into producing it. But I think it would have been stronger had Nystrom skipped the Java version and spent those pages on theory instead before jumping into the C implementation. While going through the Java stuff (implementing in C# instead because I have an emetic reaction to Java) I found myself just wanting to hurry up and get to the good stuff in C. And I found the visitor pattern and code generation stuff to be a distraction.
The code can also be a bit hard to follow at times because he jumps around from file to file and function to function. He'll present a function that calls a function that doesn't exist yet, and then define the new function, etc. He does it that way because he wanted to ensure that every single line of code was present in the book (he wrote a tool to ensure that was the case), and it certainly helps if you're trying to copy his code verbatim, but not so much for high-level understanding. Maybe that's a failing on my part.
Finally I wish he had gone into more detail on how one might implement a register-based VM because they are faster and more interesting (to me) than a stack-based one.
Re: Crafting Interpreters: A Review
#63Following a slightly different path, "Modern compiler implementation" goes over several topics mentioned in the review (lexing, parsing, type checking, code optimization and generation, runtime environments aspects e.g. garbage collection). There exists various flavors of the book (in ML, Java, and C).
There's also Thorsten Ball's Writing an Interpreter in Go[1] and Writing a Compiler in Go[2]. [1] https://interpreterbook.com/ [2] https://compilerbook.com/
Re: Crafting Interpreters: A Review
#64What other books are of the same caliber that HN would recommend?
The Elements of Computing Systems - Noam Nisan, Shimon Schocken
Operating Systems: Three Easy Pieces - Remzi H. Arpaci-Dusseau, Andrea C. Arpaci-Dusseau
Re: Crafting Interpreters: A Review
#65Without a doubt one of the best technical books I have ever read. To me, it was a missing piece of the big puzzle of "how do computers work". I read many a book to answer this question, and came away with three books: - CODE by Charles Petzold explains the CPU - Operating Systems: Three Easy Pieces by Arpaci-Dusseau explain OSes - Crafting Interpreters by Robert Nystrom explains programming languages Masterfully done…
Any defining book for networks?
Re: Crafting Interpreters: A Review
#66I'm in the middle of this book at the moment and I have mixed feelings on it. It's definitely well-written and you can feel the love and care that went into producing it. But I think it would have been stronger had Nystrom skipped the Java version and spent those pages on theory instead before jumping into the C implementation. While going through the Java stuff (implementing in C# instead because I have an emetic re…
With Truffle you start with a Java based tree walking interpreter (could use Kotlin too for less boilerplate), so the very easiest stuff. Then you annotate it in some places, add a dependency on Truffle and ... that's it. Now you have a JIT compiler for your interpreted language. The next step is to start refining the use of the annotations and to write specializations in order to accelerate your JIT by incorporating standard techniques like polymorphic inline caches.
Finally you can compile your new interpreter+JIT engine down to a Graal native image (single standalone native binary), thus ensuring it can start as fast as an interpreter written in C and can warm up as fast as V8. The binary can also be used as a shared library.
Given that this tech exists now, people who choose to write their interpreter in Java will have a massive edge in performance over people walking the traditional path. It's still relatively new technology but it's hard to see how it doesn't change interpreter design forever.
Re: Crafting Interpreters: A Review
#67Without a doubt one of the best technical books I have ever read. To me, it was a missing piece of the big puzzle of "how do computers work". I read many a book to answer this question, and came away with three books: - CODE by Charles Petzold explains the CPU - Operating Systems: Three Easy Pieces by Arpaci-Dusseau explain OSes - Crafting Interpreters by Robert Nystrom explains programming languages Masterfully done…
I will check out Three Easy Pieces! Thanks for the rec.
Re: Crafting Interpreters: A Review
#68Without a doubt one of the best technical books I have ever read. To me, it was a missing piece of the big puzzle of "how do computers work". I read many a book to answer this question, and came away with three books: - CODE by Charles Petzold explains the CPU - Operating Systems: Three Easy Pieces by Arpaci-Dusseau explain OSes - Crafting Interpreters by Robert Nystrom explains programming languages Masterfully done…
Re: Crafting Interpreters: A Review
#69Without a doubt one of the best technical books I have ever read. To me, it was a missing piece of the big puzzle of "how do computers work". I read many a book to answer this question, and came away with three books: - CODE by Charles Petzold explains the CPU - Operating Systems: Three Easy Pieces by Arpaci-Dusseau explain OSes - Crafting Interpreters by Robert Nystrom explains programming languages Masterfully done…
Re: Crafting Interpreters: A Review
#70I've been wanting to read this book, but I'm not sure how I should go about it. Are you supposed to read and type out the code examples? I'm just wondering if I will learn anything that way?
The way that worked better for me was doing the book in a different language (I did it in Crystal and Rust). I had to fully understand the intent being every code example so I could translate it correctly. This adds another layer of difficulty, depending on how comfortable you are with Java and the language of your choice, but it was the way that worked better for me. I truly felt that I created a language, not just…
In my case, I chose to use C++ (more specifically, C++20 under GCC 11) with minimal external dependencies (currently just Boost for memory mapped IO and fmt). I'm working on the second part of the book now (only just getting started, really). My tree-walking interpreter works, but does have some limitations (I currently leak memory in a few locations, such as closures, due to reference-counting cycles).
I've had a few gotchas following along this way, but it's been entirely due to my choices.
One thing I'd highly recommend doing: setup tests to validate your code immediately! I don't have anything fancy setup, but basically what I have is mechanisms to hand a script to my interpreter and capture stdout/stderr. It's not the best level of testing, for sure, but it does allow me to basically place the lox snippets from the book into a reproducible framework to make sure my interpreter is doing what's expected. I also added tracing/memory dump facilities to my tree-walker to facilitate debugging as well (the byte-code interpreter builds this in from the start, so I've not deviated in that aspect, yet).
I'm really enjoying the book. It's definitely created a spark in me I've not felt in quite a while.