Why Zig?

3 points by jakeStbu 14 hours ago

I'm primarily a C dev (with x86_64 assembly experience and a little Rust), and I simply don't get what the major benefit of Zig is. From what I hear, it's meant to be simple and have no macros, but rather "calling functions at compile time". I also hear that it's primarily a C alternative. To me though, I simply don't understand how a language being simpler makes it better - if anything, it means it has less functionality! Besides, C is already such a simple language in terms of how close it is to Assembly and how readable it is, so what's the actual benefit? Macros are quite useful IMO, so having a lack of macros doesn't seem like a selling point to me. I would appreciate some clarity on this because this just doesn't really make sense to me.

GianFabien 11 hours ago

I can't bring myself to like or to learn Zig syntax. BUT I do appreciate the cross-compilation capabilities of Zig and use it with C source codes. I find the Zig way of supporting multiple instruction sets and run-time environments simpler to grok than the GCC/Clang approach.

One day, I might use the Zig tooling to translate my C sources to Zig sources and continue development in Zig from that point forwards.

  • jakeStbu 10 hours ago

    Yeah building a C cross compiler can certainly be a pain. I do feel like basically every Zig improvement over C also exists with Rust, though, including, yes, ease of cross compilation.

troymc 13 hours ago

Maybe ask ChatGPT?

  • jakeStbu 13 hours ago

    ChatGPT is not particularly smart and tends to generate answers which should not be trusted. Of course, I have done Google searches before this, but most of them just point to the same answer - "It's C but simpler".

    • troymc 13 hours ago

      In some ways, Zig is simpler than C, it's true, but it also adds some nice things.

      For example, Zig introduces a robust error handling mechanism (try, catch, return err) that eliminates the need for exceptions or manual error checking via return codes (if (ret < 0)).

      Also, Zig includes its own build system (zig build) and package management. This removes the need for external tools like make, cmake, or third-party dependency managers. Everything is integrated and works cross-platform out of the box.

      You wondered why getting rid of macros was a good idea...

      Zig allows compile-time function execution (CTFE) as a core language feature. This replaces the need for macros in many cases. While C macros are powerful, they are also error-prone and hard to debug. Zig's comptime feature allows you to write functions that run during compilation, offering the same benefits but with stronger type safety and clearer error messages.

      • jakeStbu 13 hours ago

        I see. Better error handling could perhaps be something that C can improve, yes, especially as compared to things like errno (which yes is technically not C specific but rather Linux specific, but it would be good to have a layer of abstraction over this). I can see why Zig Build may be useful - does it have any major advantages over something like, say, Rust's Cargo? I personally find that to be quite powerful. CTFE does sound like it could be easier to debug, but it sounds significantly less powerful and I don't think that it's necessarily worth it in many cases.