←back to thread

Zig is hard but worth it

(ratfactor.com)
401 points signa11 | 1 comments | | HN request time: 0.209s | source
Show context
LispSporks22 ◴[] No.36152905[source]
> Only time will tell if comptime is the "greatest thing since sliced bread" or not.

Common Lisp user here. Am I missing anything that Zig has in the compile time department?

edit: Also, does the code in the comptime block have to be valid Zig?

replies(2): >>36153755 #>>36154118 #
1. kllrnohj ◴[] No.36154118[source]
Personally I think comptime is a questionably design and is something both Rust & C++ did much better.

In C++ branches that don't have to "compile" are explicitly marked as such with `if constexpr`. In Rust you've got macros that are also explicit with required `!`. In Zig any branch can be a ticking code rot time bomb, just like it was with C #ifdefs. It's better in Zig in that it at least has to parse and so you've got fewer blatant problems, but the category of problems of "I flipped DEBUG from `false` to `true` and now I have dozens of build errors to go fix" is still there. And you really don't have any warning signs other than "this is branching on something that might be known at compile time"

But honestly that's also my general impression of Zig as a whole. It's very definitely a "better C", not something that's necessarily good/competitive with the broader state of the ecosystem. It's like a love letter to C, completely with many of the same general problems that C is known to have and that other languages have addressed.