2021 side projects

January 01, 2022

During the year 2021 I had 2 main side projects, both of which were an excuse to learn and play with Rust (btw, I bought a physical copy of the Rust book, as they call it, and it’s great).

Furthermore, both of these projects are based on books, as we’re going to see.

Ray tracing in one Weekend

The first project is based on the Ray tracing in one weekend book. As the name of the book suggests, we incrementally build a Ray tracer in C++, and the project is supposed to keep you busy for one weekend. But instead of using C++, I did the project in Rust. I must confess that it took me several weekends to complete though!

All in all the project was very fun, and I think it’s a good starting point for learning Rust, and you do not need more than a vague knowledge of C++. Besides, the visual feedback that you get on your code is very rewarding. Here is the image I generated by the end of the book:

Note: in the above link, we can see a book series, I only did the first volume, but I might do the others later.

Crafting interpreters

The second project is based on Crafting interpreters. Another book with an explicit name - it challenges the “reader” to build an interpreter for a Javaesque scripting language (*), in Java. I bought a physical copy of the book, and it’s massive!

As one can already guess, I exerted myself to use Rust instead of Java. As a side note, using Rust allowed me to skip some paragraphs of the book, indeed the author uses the Visitor pattern, which is usually used to compensate the absence of pattern matching facilities. But Rust has pattern matching, so I just used it, and I think it saved me quite some time (and led to slightly cleaner code in my opinion).

On the other hand I stayed stuck for a long time at some point because I wasn’t aware of some Rust idioms (notably the Rc<RefCell> idiom) - I might write about that some day.

The book provides great explanations and illustrations, and as for RTIOW, I think it is a great vehicle for learning Rust (despite the caveat I expressed above). The book is actually split in 2 parts:

  • first building a tree walk interpreter
  • then build a full fledged compiler in C, all the way down to machine code (going through Virtual machine code)

To be frank I have only finished the first part as of today - it’s been very fun and informative!


Profile picture

Written by Vincent Perez, a polymorphic software developer.