3 ms·
(TL;DR; Zig isn't simpler than Rust from an implementation perspective, quite the opposite. And the respective compiler size is a good illustration of that poin
by littlestymaar 5y ago
(TL;DR; Zig isn't simpler than Rust from an implementation perspective, quite the opposite. And the respective compiler size is a good illustration of that point)
> Simply because it's simple
But by what metric? For instance, why do you consider comptime being simpler than macros? Macros are a dedicated tool built for one specific job (compile-time pre-processing). Comptime means re-using the same syntax for both compile-time and run-time execution. Yes it is pretty elegant, and I like it but it is more complex that the Rust model because you now have a tool that needs to work with both cases.
Same async, Rust has async functions and regular function, Zig has functions that are automagically coerced to the right type by the compiler. Is it ergonomic, probably (but not always), but it's much more complex to implement under the hood.
Last but not least: memory safety, Zig's goal is to achieve a reasonable level of memory safety by using a collection of built-in sanitization tools. Those tools are much more complex than the borrow-checker (which rely on 2 simple rules: move semantic and shared XOR mutable)and for the most part they don't even exist!
Zig's goal is developer ergonomics, and it's really cool to see radical experimentations in that space (and as I said, what zig has done with regard to cross-compilation is inspirational for every language author on this planet) but it's not simplicity. Otherwise, the Zig compiler probably wouldn't be 120% bigger than the rust one right?! (Rustc has 1.6 million loc[1], Zig has 3.5[2], more than twice as much.
[1]: https://tokei.rs/b1/github/rust-lang/rust https://tokei.rs/b1/github/rust-lang/rust
[2]: https://tokei.rs/b1/github/ziglang/zig https://tokei.rs/b1/github/ziglang/zig
- AndyKelley 5y agoUm that lines of code figure is nowhere near accurate. I reported recently[1] that the zig compiler is 140,331 lines. [1]: https://mobile.twitter.com/andy_kelley/status/1453910640943271941 https://mobile.twitter.com/andy_kelley/status/14539106409432...
- littlestymaar 5y agoOh, interesting, thanks. Do you have any idea of where all that code comes from? (I'm a big fan of your work btw, I'm just really sad that a few people on this forum seams to like Zig for the sole reason it's not Rust)
- AndyKelley 5y agoyeah I agree, it's one of my least favorite reasons that Zig gets mentioned. All what code exactly? Here's a file-by-file breakdown of the line count: https://clbin.com/iuMTn https://clbin.com/iuMTn