Hacker News new | ask | show | jobs
by ChadNauseam 214 days ago
I know this post is AI generated to some extent but I'm still curious. The subtitle says:

> Rust shouted about safety. Zig just built it — without the ceremony, the sermons, or the 15-minute compile times.

Which I interpret as meaning that zig delivers memory safety in a simpler way than rust. But a few paragraphs in, it says:

> Rust teaches you ownership like a tough-love therapist. Zig, meanwhile, just shrugs and says, "You break it, you fix it." That's the philosophical divide. Rust assumes you can't be trusted. Zig assumes you're an adult.

Does this mean that zig's safety depends on trusting the programmer to write correct code? This wouldn't necessarily be a bad thing if zig makes correct code simple to write or has other advantages, but if incorrect code is allowed it makes sense why the compiler can be more permissive and I wouldn't say it's quite delivered the same thing as Rust.

Ok, another thing:

> Zig looks boring. Feels boring. Reads like a C project written by someone who finally went to therapy.

    pub fn main() void {
        const stdout = std.io.getStdOut().writer();
        stdout.print("Hello, World!\n", .{}) catch unreachable;
    }
> That's it. No macros. No build.rs. No Cargo screaming about outdated crates.

Am I crazy or does this not actually look simpler than

    fn main() {
        println!("Hello, world!");
    }
Is the zig version doing something other than hello world? Or did the author, in their post about how zig is simpler and more readable than rust, choose a code example where the corresponding rust code would be much simpler and more readable?
4 comments

Zig's memory safety has nothing in common with Rust. I'd even say, it mostly has barely more than C. It gets reliability from proper error handling.

It has a very weird feeling complaining about build.rs when any semi-serious Zig project comes with a build.zig that's always more complex than any build.rs.

Logical contradictions in AI slop? Unthinkable!

But to address the serious question: We can't have all three of: a simple language, zero-cost abstractions, and memory safety.

Most interpreted language pick simplicity and memory safety, at a runtime cost. Rust picks zero-cost abstractions and memory safety, at an increasingly high language complexity cost. C and Zig choose zero-cost abstractions in a simple language, but as a consequence, there's no language-enforced memory safety.

(Also, having a simple language doesn't mean that any particular piece of code is short. Often, quite the opposite.)

There is a simpler version for zig.

    pub fn main() !void {
        std.debug.print("Hello, World!\n", .{});
    }
The only difference is this writes to stderr and does not fail (and explicitly says it is meant for debug), while their example writes to stdout. In zig if you want to write to stdout you need to explicitly pick the std and handle all the details (like error handling).

He gave the possible worst example, this article is nonsense.

> Zig assumes you're an adult.

I hate this line of thinking. It doesn't matter if I'm an adult, if the guy before me was a screaming toddler.