Advent of Zig

Lessons learned by attempting Advent of Code 2024 in a language I was a novice in.

The goal

My goal in the winter of 2024 became clear; I wanted to finish Advent of Code and I wanted to do it in Zig.

Up to this point I had only written a few limited programs that manipulated text or played tones out of my sound card. I imagined that if I was required to solve more complicated problems in the language I would be forced to learn a larger distribution of concepts in the language. So that’s what I did.

What I learned

  1. Solving problems is difficult when you’re simultaneously adjusting your mental model of a language.
  2. Python is better for prototyping, experimenting, and building a solution when you haven’t completely solved a problem but you’re almost there.
  3. Learning how to debug is essential to solving any decently complex problem. Even if it’s as simple as print debugging.
  4. Study the standard library! It’s harder to think of abstractions if you don’t know how things work across the standard library. You can’t just drop-in abstractions that work in other languages. And you may often be reinventing the wheel.
  5. Zig can compile very fast very small executables.
  6. When you’re writing one solution a day during the holidays, the amount of time you save writing a working solution is much more important the runtime of your solution.
  7. The general purpose memory allocator is great for finding leaks in your code. No valgrind!