Nathan Franck
Nathan Franck

Posted on

Effective stubbing using unreachable

I'm working on a pretty long-form project for a game-runtime using a directed graph structure at it's core, and I'm really enjoying using Zig, for a variety of reasons!

One thing that has really been keeping me sane recently is the use of unreachable. I can do a small 30 minute session of programming, and feel accomplished at the other side, because my code compiles, makes sense to me, and is sprinkled with TODO messages of places I have yet to accomplish, thanks to this one keyword.

Here's the end-state I got to in my code today:

Image description

Obviously, I haven't implemented my magic function, but I can get it to compile, run my test, and observe some output that seems okay! Sounds like a job done for today!

unreachable keyword with a TODO comment directly afterwards is a great signpost to myself that I would love to get to this later, but I need to call it quits and get back to life (sleep) for now. Good night.

Top comments (1)

gonzus profile image
Gonzalo Diethelm

I have seen Andrew use this several times when he used to stream while writing the Zig compiler. I believe he used @panic("TODO: blah"), rather than @unreachable, but the basic idea is the same.