Zig vs Rust. Which one is going to be future?

I think about pros and cons and what to choose for the second (modern) language in addition to C.

@[email protected]

  • onlinepersona@programming.dev
    link
    fedilink
    arrow-up
    12
    ·
    edit-2
    26 days ago

    Is zig memory safe by design? If not, rust will “win”. Large companies aren’t going to hire for an unknown or unpopular memory unsafe language when they already have C or C++ - there’s just no contest.

    Last I read, zig didn’t even have a standard string library. Unless that changes, it won’t even be a viable alternative to C/C++.

    Edit: I checked and got this

    the Zig language, like C, entrusts memory management to humans, placing full trust in human development. Zig then provides some memory safety checks to ensure memory safety. However, it still lacks the strict compile-time guarantees of Rust’s ownership system and borrow checker. Therefore, when writing Zig code, developers need to pay more attention to potential memory safety issues and ensure that errors and exceptional situations are handled correctly.

    Rust Magazine

    Anti Commercial-AI license

    • PushButton@lemmy.world
      link
      fedilink
      arrow-up
      2
      arrow-down
      3
      ·
      26 days ago
      • Zig uses allocators, which will inform you if you are leaking memory.
      • Zig comes with defer/errdefer to simplify the resource cleanup (and for ergonomics).
      • Zig comes with Optionals to manage nulls.
      • Zig comes with slices (ptr + size) to manage all the bound-checking.
      • Zig automatically check for overflow/underflow arithmetic.
      • Zig will check for pointer alignments when casting between pointer types.

      => Zig is designed to make you do it right easily, and very hard to do it wrong.

      In other words, Zig will let you be, but warn you when you are doing something wrong, where Rust is like Karen who is always screaming at you for every word you are typing.

      To summarize, you really need to /want/ to fuck up to fail your memory management… If after all that you still can’t manage your memory, it might be better for you to look for another carer.

      Something is sure thou, Zig is very safe - just as it’s safe to cut my veggies with a knife. I might cut a finger and bleed a little bit, but I will not use plastic knife “because it’s safer”.

      Moreover; You are talking like if Rust is safe, all the time, which is not true in reality:

      52.5% of the popular crates have unsafe code. Therefore, in an average real-world Rust project, you can expect a significant number of the dependent crates to have unsafe code – Source

      Basically, you’re comparing a hypothetical world where Rust is always safe to a superficial glance at Zig’s capabilities to claim a “winner” here.

      And for the String library… Are you fucking serious? Do you want to compare the Zig’s Std library versus the famously tiny Rust Std library? Really?

      • calcopiritus@lemmy.world
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        17 days ago

        A crate having the unsafe keyword doesn’t make the crate unsafe. The unsafe keyword just tells the compiler: “I know that what I’m trying to do may lead to memory safety issues, but I, as the programmer guarantee you that the codeblock as a whole is safe, so turn off some of your checks”.

        Using the unsafe keyword in rust is no much different than using a C library in rust.

        • PushButton@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          17 days ago

          It’s when you’re at the point of saying that unsafe is safe, it’s the point where you should just shut it up kid…

          • calcopiritus@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            17 days ago

            I don’t know why you are being so rude. I thought it was the rust community that was known for being toxic?

            It’s not my opinion on what the unsafe keyword means. That’s its purpose. Nobody ever wants to write unsafe code on purpose. The unsafe keyword was created to allow safe programs to be created in rust that wouldn’t be accepted by the strict rust compilers.

            In a Venn diagram, there are 2 circles: safe programs (1) and programs that are deemed safe by the rust compiler (2).

            Circle 2 is smaller than circle 1 and entirely contained inside it. However, there is no reason to not let people write programs from circle 1 that aren’t in circle 2. The unsafe keyword exists to enable programmers to write those programs in rust. However, it comes with a warning, now the programmer is the one responsible for making the program inside circle 1.