‹ 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. rvrb · · focus · HN ↗
          there has been a ton of work on making comptime a pure and deterministic execution environment. I do not expect that work to stop. I don't know where you are getting the idea that it is not an important design consideration for the language.

          to expand, if two different host platforms cross compiling to the same target platform have different results, I am almost certain that would be considered a compiler bug.

          if you're pointing out that a runtime operation and a compile time operation might not agree, I'd be more interested in understanding when that would ever have any meaningful impact on anything. given the compilation is supposed to be deterministic, the difference can easily be addressed by comptime branching on target architecture in the rare case that it matters for your program.

          1. weinzierl · · focus · HN ↗
            Determinism and host/target agreement are two different properties. I meant the second one.

            It's something Rust guarantees (without me having to take care of it e.g. by manually branching) and Zig does not.

            1. rvrb · · focus · HN ↗
              sure, it sounds like there is a difference here. I'm not aware of any stance by the Zig core team on the subject.

              I am genuinely interested in a place that this matters for a program, or any practical consequence this has for an end user of the language.

              no idea why your response was flagged originally.

              1. weinzierl · · focus · HN ↗
                The practical value is that moving a computation from runtime to compile time can then be purely an optimization, rather than potentially changing its semantics. Think generated lookup tables or numeric constants. Ideally f(x) means the same thing whether evaluated by the compiler or by the generated program.
                1. chaz72 · · focus · HN ↗
                  > Ideally f(x) means the same thing whether evaluated by the compiler or by the generated program.

                  Absolutely, that’s why I wanted to know what types of things aren’t covered yet, and that’s also why I don’t share your certainty that they won’t be resolved later.

                  1. weinzierl · · focus · HN ↗
                    You'd have to read the discussions the Rust community has about this to get a picture. It's complicated.

                    From what I understand, there is hope for sqrt but there is no consensus on transcendentals.

                    1. chaz72 · · focus · HN ↗
                      No worries, I take your word for the status of these in Rust and I don’t need those features in my own Zig comptime code which as I said in a different comment, has been very predictable over the last few years. Thanks for explaining though!
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.