‹ BackHN Continuity

Thread

What Zig felt like, coming from Rust

282 points · 351 comments · ksec

  1. weinzierl · · focus · HN ↗
    Two additional points:

    1. Tooling (as an extension to the mentioned IDE support point). Zig and Rust are both praised for their tooling and I think rightfully so. The C/C++ interop story and the cross-compiling story in Zig are great. From the standpoint of a working practitioner though I think Rust is way ahead. Not surprising given that Zig is much younger, but something to keep in mind.

    2. Compile Time Stuff: Here Zig is praised and Rust not so much. I think this is undeserved. Rust has much higher aspirations for their compile time features, namely that outcome must be identical regardless when the code runs. This is a very useful property but makes the task much harder and fundamentally incomparable with Zig comptime.

    1. chaz72 · · focus · HN ↗
      Are you saying that you think that Zig does not produce identical outcomes for comptime code regardless of when the code runs? What do you mean?
      1. weinzierl · · focus · HN ↗
        Yes. For example in Rust it took a long time for floating point operations to be available at compile time and even now only a subset is. The reason is that a lot of energy and thought went into the issue of producing identical output (and what identical precisely means ) even when compilation is on a different processor than where the target runs.

        As far as I know this is not a concern for Zig comptime.

        1. nvme0n1p1 · · focus · HN ↗
          What's your source for this? Comptime Zig code can do pointer casts and whatnot, all emulated as if run on the target bitness/endianness/etc. And any operations that are undefined on the target platform result in a compile error. I've never had an issue cross-compiling.
          1. weinzierl · · focus · HN ↗
            Endianness and pointer casts are the mechanical part and I would expect Zig to emulate them correctly.

            Other parts, like floats are harder. This is where a difference shows. Rust is like: "Sorry, since we cannot uphold our guarantees, no transcendentals for you at comptime ", whereas Zig is chill about that and let you have your transcendentals even if results may differ between comptime and runtime. Different mindsets.

            1. simonask · · focus · HN ↗
              Just to note, Rust has had compile-time floats for a while now, but yes.
              1. weinzierl · · focus · HN ↗
                Yes, but no transcendentals on floats. You can add them and the like but you cannot calculate the sine.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.