Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Interesting article but I disagree with conclusion.

Namely these two do not compute:

> if you choose the C-way manual memory management, you will make programmers debugging their code for long hours with the hope that -fsanitize=address would show something meaningful

> Zig can still be used in large systems projects like web browsers, interpreters, and operating system kernels – nobody wants these things to freeze unexpectedly.

But Zig isn't meaningfully safer than C. So you still get to debug code for long hours hoping you'll spot the error.



Zig isn't meaningfully safer than C

it's not? why would anyone bother using it then?


Because it's not Rust/C. And it does have some nifty features like tagged unions and comptime.

Here is Zig UB in a nutshell

    const std = @import("std");

    pub fn main() !void {
      const warning1 = try powerLevel(9000);
      const warning2 = try powerLevel(10);

      std.debug.print("{s}\n", .{warning1});
      std.debug.print("{s}\n", .{warning2});
    }

    fn powerLevel(over: i32) ![]u8 {
      var buf: [20]u8 = undefined;
      return std.fmt.bufPrint(&buf, "over {d}!!!", .{over});
    }


I haven't my used Zig much, but I suspect that in practice Zig is much safer, even if only because it's more expressive.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: