Ask HN: Writing an Interpreter in Go or Crafting Interpreters?
35 points by lordleft 2 months ago | 27 commentshttps://interpreterbook.com/ https://craftinginterpreters.com/
- stefanos82 2 months agoRead both if you like.
I read and liked them both, but my heart belongs to Bob's writing, especially the C implementation in Crafting Interpreters and how he explains things.
- wduquette 2 months agoCrafting Interpreters is the right at the top of my list of favorite programming books…and I’ve been reading them since the late 70’s. Amazingly clear and well-designed.
- __rito__ 2 months agoMay I get the list of your favorite programming books?
- wduquette 2 months agoHeh. The books on the list would be the ones from which I learned new ways to think about programming. Most of them are now long out-of-date, as witness the discussion on "101 BASIC Games" going on elsewhere on Hacker News.
"101 Basic Games", edited by David Ahl and published by DEC. I learned to program by typing in the code from this book back in the late '70's.
"Write Your Own Programming Language Using C++", by Norman E. Smith. This is about writing a simple Forth interpreter. I used what I learned to write a simple Forth interpreter in C, which I then used as an embedded extension language in a couple of apps I was working on at the time. This was on a VAX, and rather before I'd ever heard of anything like TCL/TK.
"Tcl and the Tk Toolkit", by John Ousterhout, which (among other things) explained how an embedded extension language ought to work.
The O'Reilly X Windows books, and various O'Reilly books with animals on the cover. They were essential references, back in the day.
"The C++ FAQs", by I don't remember who. I never used C++ much; but this book was an excellent introduction to all of the pitfalls in the C++ of the day, and how to use C++ without shooting yourself in the foot--and an even better example of how to write for programmers. It was a big influence on how I later wrote programmer's documentation.
"Refactoring", by Martin Fowler. I've never followed the advice in this book slavishly, but it's tremendously affirming to read a new book encouraging you to do what you were doing already without having a name for it.
"Effective Java", by Joshua Bloch, which I spent a lot of time with about ten years ago; it helped me come to grips with Java and avoid a variety of foot-guns, much like "The C++ FAQs".
Various Lisp books; I don't like Lisp all that much, or Scheme either; but I come back to one or the other every few years and take another look, because I always learn something.
Various other texts on specific programming languages, as I experiment with them; "Learn You a Haskell for a Great Good" sticks out mostly because it has a memorable title.
And "Crafting Interpreters", which I've worked all the way through and then run with. Last month I implemented a simple Datalog implementation in a few days using the techniques from CI; I'll soon be integrating it into a much enhanced version of Nystrom's Lox.
- ferguess_k 2 months agoJust to add that the C++ FAQ has been made free (along with other FAQs) and hosted here:
- __rito__ 2 months agoThank you for the list!
- ferguess_k 2 months ago
- wduquette 2 months ago
- __rito__ 2 months ago
- greybox 2 months agoI recommend skimming over the first few chapters of crafting interpreters, the main value there is the recursive descent algorithm and abstract syntax trees, the rest is implementation. I've been developing my own language [1] and that's how I got started
The ideas in crafting interpreters are not language specific, the examples are in java, but I used C++ for instance. Im sure you could transfer the same ideas to Go. Then again I've never read the go book you are referring to
- eleventhborn 2 months agoIf you go with Crafting Interpreters, there is a coding challenge on CodeCrafters that follows the book: https://app.codecrafters.io/courses/interpreter/overview
It is free (for now) and it helps me focused.
- SwiftyBug 2 months agoI'm doing Crafting Interpreters... in Go! The book uses Java, but I prefer Go so I just went with it. It was an interesting exercise to "translate" the understanding of the implementation shown in the book (which relies heavily in OOP) to something more idiomatic in Go.
- kgabis 2 months agoI went over "Writing an Interpreter in Go" and "Writing a Compiler in Go" but instead of doing it in Go, I did it in C. In hindsight it was a very good decision, because it forced me to write the code myself, instead of mindlessly copying it. After finishing the books I've spent some time extending the compiler I've written and I've published it on github (https://github.com/kgabis/ape). I've read Bob Nystrom's previous book, so I'm sure Crafting Interpreters is great as well, but I really recommend Writing an Interpreter/Compiler in Go.
- __alexander 2 months agoCrafting Interpreters has been sitting on my shelf for two or so years. I would love to read the book but the use of Java shelved it. I don’t have the time to understand the concepts from the book while simultaneously learning Java.
- vips7L 2 months agoBob uses basic programming constructs. If you know any language you can follow the book.
- __alexander 2 months agoYes, but half the code in the book is implemented in Java.
- blenderob 2 months agoYou can use Python or anything else you like to implement your code. The Java code he writes is simple, imperative code. But the OOP stuff might get in the way. If you've got programming experience, it isn't hard to read it and write your own in your preferred language.
- FusspawnUK 2 months agoIts easy to follow along with, I did my implementation in c#, Likely even easier now you can just feed the java to chat gpt and have it translate to <insert favourite language here>.
- markus_zhang 2 months agoOr you can simply jump to the second part in C. I don't think it's mandatory to read the first part for the second one. Plus the second part is more interesting as it implements a VM.
- blenderob 2 months ago
- __alexander 2 months ago
- vips7L 2 months ago
- Spartan-S63 2 months agoI've read Writing an Interpreter in Go and Writing a Compiler in Go. Crafting Interpreters is on my bookshelf and on the list to get through Soon™. The latter books by Thorsten Ball are an incredibly approachable introduction to the topic. It's how I initially learned Go and it reinforced what I learned back in my undergrad on how parsers and compilers work.
I love writing parsers and get far too few opportunities to flex that muscle. I wish I had read Crafting Interpreters for this question, as well, but by all accounts it's an incredible tome, as well. Read them all and see what different information you pick up from them!
- markus_zhang 2 months agoI only read Crafting Interpreters and I can recommend this one. It's also free as a website so you can evaluate it before making a purchase. I did think it is interesting enough to go straight to make the purchase.
- agarren 2 months agoI really enjoy Crafting Interpreters, but I’ve revisited it a couple times and haven’t yet made it through half the book. It’s very well written and there’s a lot of material to chew on. That said, Writing an Interpreter in Go, is short, sweet, and the Pratt Parser implementation and explanation are great! I haven’t cracked open his compiler book yet, but the interpreter book was a breeze.
- markus_zhang 2 months agoYeah I agree lox has a bit of too many features. I didn't complete the interpreter part and now I'm diving into the VM part. I'm not particularly interested in the more advanced stuffs. I won't get a compiler job anyway.
- markus_zhang 2 months ago
- agarren 2 months ago
- dusted 2 months agoThere's also an excellent tutorial from LLVM, it got me started, I got some ideas and didn't want to be too influenced by "the right way", so I stopped somewhere mid tokenizer.. But I have a turing complete, interpreted language as of now, that I'm having a lot of fun thinking about.
https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index...
- MeetingsBrowser 2 months agoThe kaleidoscope tutorial is a good tour of LLVM capabiltiies, but I don't think I would consider it an alternative to either of these books.
- MeetingsBrowser 2 months ago
- FusspawnUK 2 months agoCrafting interpreters is still the one book that made me truely understand how they worked. always get's a vote from me!
- angra_mainyu 2 months agoI started them but dropped them and went straight for:
- Engineering a Compiler
- Programming Language Pragmatics
- Crafting a Compiler
Quite doable, particularly if you focus on one and supplement with the other two.
- MeetingsBrowser 2 months agoWhy drop them? If you have time for 3 books, you can probably find time for 5. Writing an Interpreter in Go and Crafting Interpreters are both great, and much more fun than these.
- MeetingsBrowser 2 months ago
- MeetingsBrowser 2 months agoBoth are great!