Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Assorted thoughts on Zig and Rust (2020) (scattered-thoughts.net)
12 points by ducaale on Aug 9, 2022 | hide | past | favorite | 4 comments


It is really interesting to see the trade offs. I have never read something before from someone who was familiar with both languages.

The comptime reflection in zig seems particularly powerful. Proc macros are just so difficult to write that I often just introduce a bunch of code duplication instead. As const rust gets better and better, I wonder if you could eventually add something like comptime to rust.


It is very good comparison, I've recently switched to Zig from rust so I can answer some questions if you're curious.

Regarding comptime, it's not just that you basically have proc-macros available everywhere and you just need to use one keyword. It's rather a combination of comptime, duck-typing (comptime functions often take any type/struct/tagged-union), lazy-evaluation (only used functions are type-checked) and memoization (comptime is guaranteed to point to the same memory so you can easily do string interning for example).

That together with introspection and ability to unroll loops in comptime make it very easy to do any kind of meta-programming. You can also throw compile time errors and do various assertions yourself, so while it's true that Zig by default is not as memory-safe as Rust, it is also true that it's very easy to add custom checks which you couldn't do in rust. Or it wouldn't be so easy so you wouldn't do it.

Also pointers are not so scary in Zig, especially if you know that certain things live only until end of frame for example and then you can scrap everything. This is also possible in rust but people don't do that so much.

But to be honest, I think I've learned a lot about safety in Rust and it definitely made me better programmer, I just don't want to do it anymore :)


I'll paraphrase something I once heard, -- "There are two types of Rust programmers: 1) Functional programmers who want to go fast/er, and 2) those that want to type check their assembly." This is an article for type 2).


It's a really good review / set of thoughts, mostly still representing the current understanding of Rust and Zig.

Currently the page 404's, this (still) does work:

    https://webcache.googleusercontent.com/search?q=cache:_Xrwm0yymL4J:https://scattered-thoughts.net/writing/assorted-thoughts-on-zig-and-rust/




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

Search: