Assorted thoughts on Zig and Rust (2020)(scattered-thoughts.net) |
Assorted thoughts on Zig and Rust (2020)(scattered-thoughts.net) |
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.
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 :)
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/