This is really interesting:
Zig has comptime
Plenty of languages have metaprogramming, but none are exactly alike. C’s preprocessor won’t prepare you for Zig’s compile time execution. Macros won’t prepare you for it. The run-time introspection of various dynamic languages won’t prepare you for it either.
Zig’s
comptime
is its own thing. And you’ll need to learn about it or you’ll run into errors early on that otherwise won’t make sense because it’s happening whether you ask for it or not.Within a specific set of rules (including the explicit use of the
comptime
keyword), “regular” Zig code will run at compile time, resulting in a runtime executable with values pre-calculated, unneeded code removed, loops “unrolled”, and code generated inline to work with different data types.Why that’s good: Only time will tell if
comptime
is the “greatest thing since sliced bread” or not. But so far, it seems to be a pretty solid concept. By executing portions of the program at compile time, a large number of tricky language problems have been solved without introducing too many additional concepts.
I’ve often wished for better metaprogramming in other languages – having metaprgramming in the same language is neat!