Read Crafting Interpreters

2024-01-23

Should you read Crafting Interpreters by Robert Nystrom? Yes.

Why?

It may seem like you do not have to learn the inner workings of a programming language and its runtime because you do not work on programming languages, you just use them to build other things. For the most part, this is a fair argument. The realm of language implementation, compilers, interpreters, and virtual machines exists one level of abstraction lower than what you need to actually use a given programming language. What's more is that if these things are well made, the user should seldom need to break out into that level of abstraction to understand something about the language. The compiler should just work, the error messages the interpreter spits out should be clear, the syntax should leave no room for ambiguity, etc.

But if you are a software engineer, surely you have some interest in programming languages. You certainly have a preference for a certain flavor of language, so why not learn the inner workings of one so you can learn what it takes to build your ideal language?

Robert Nystrom walks you through the implementation of Lox, a dynamic interpreted language, in Crafting Interpreters. He starts from the ground up, assuming the reader has experience programming, but only minimal knowledge of language design and implementation. He walks through 2 implementations of Lox, a tree-walk interpreter in Java and a bytecode virtual machine implementation in C. Between the 2 implementations, you will learn how to represent program text as a stream of tokens and scan, parse, and interpret them.

That is just a high level overview about the book's content. Nystrom goes into several techniques, algorithms, design decisions, compromises, and data structures to get Lox working. If you ever wanted to learn how to implement an AST, hashmap, closures, etc. from scratch, look no further than this book. As with anything in programming, the problems and solutions discussed in this book can be generalized and applied to areas beyond programming language implementation. I may or may not want to create my own language in the future, but I am grateful to Nystrom for introducing me to a grab-bag of programming techniques and solutions I can apply elsewhere.

The book is free to read online; it would be a disservice to yourself to not take advantage of such a good education resource.

Hey, I am currently looking for an engineering role. If you got this far, consider adding me to your team. Check out my resume and email me.