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

I strongly disagree. I can see why you would want to use Zig, especially if you absolutely need complete low level code and only care about pretty decent memory safety (which is valid in many scenarios). But if those don't apply Rust is much nicer.

Stuff like string manipulation is almost as painful as it is in C.



I strongly agree with your statement overall, but not in details.

Regarding string manipulation, Zig has slices and comptime-checked `printf`, so that makes string handling _massively_ more ergonomic than in C. But, yeah, managing the lifetime of the printf-ed is a pain in the back, and Rust is _massively_ more ergonomic there, if managing individual string allocations is what you want to do. (though one cool thing that Zig makes easy is comptime asserting that stack-allocated buffer has the right size for the given format string).

But, I do find Zig surprisingly ergonomic overall! For example, I have two Rust crate for writing glue code utilities, xflags (argument parsing) and xshell (shelling out). For TigerBeetle, I wrote equivalents:

* https://github.com/tigerbeetle/tigerbeetle/blob/main/src/std...

* https://github.com/tigerbeetle/tigerbeetle/blob/main/src/she...

What I found is that the Zig version is significantly easier to implement and to use, for me. In Rust, those domains require macros, but in Zig it's all comptime. And memory management is relatively easy --- flags live until the end of the program, shell is just using shell-scoped arena. I am contemplating rewriting my personal scripts at https://github.com/matklad/config/tree/master/tools/gg to Zig for that reason. Though, Zig not being 1.0 _is_ a problem in that context --- I touch my scripts only rarely, and I don't want to be on the hook for upgrades.


As far as I can tell, Zig's niche compared to Rust is to specifically cater to certain design patterns that C and C++ support, but other languages don't. E.g., anything that uses pointer manipulation for business logic.


I think it's more about low level control of allocation.

You can do "pointer manipulation" in safe Rust if you need to - anything that uses arena indices is basically that, e.g. petgraph.

The language wasn't really designed for it though so it isn't exactly integrated into the syntax.

But controlling allocation precisely is quite difficult in "normal" Rust.

Tbh I don't think it is actually that far away from Rust. It's aimed more at low level stuff, whereas Rust aims to do every level. It is more "trust me bro" than Rust's "no I'm going to check" safety. And comptime is pretty different to Rust's approach (arguably better).

But apart from that they seem to have very similar goals.




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

Search: