On the Zig vs. Rust debate, people like to focus on memory safety, but Rust's RAII is just as important to writing clean, maintainable code.
-
On the Zig vs. Rust debate, people like to focus on memory safety, but Rust's RAII is just as important to writing clean, maintainable code.
There is something truly magical about seeing my GPU driver cleaning up dozens of nested GPU and host objects when the GPU job completes. Always exactly then, never too early, never too late, never leaking anything. That's all thanks to RAII and automatic Drop calls.
`defer foo.deinit()` really doesn't cut it. You have to explicitly write it, and it only works if all code paths free the object at the end. `errdefer` is just a special case, and then the only way to know if you forgot it is by testing with a leak checker. And then the deinit function has to manually deinit all child objects.
All this stuff is just done automatically in Rust. Most of my types don't even implement Drop, or only do something trivial there, because the compiler recursively dropping objects is 99% of the work.
It's *knowing* the compiler is on your side and taking care of all this that makes it magical. If you have to write out the code by yourself, that's more work, and a huge chance for bugs. The compiler is doing some very complex tracking to figure out what to drop when and where. You'd have to do that all in your head correctly without its help.
-
HAMMER SMASHED FILESYSTEM πΊπ¦replied to Asahi Lina (ζζ₯γͺγ) // nullptr::live last edited by
@lina rust might be good for business
but forth makes you feel and love
-
Matthew Millerreplied to HAMMER SMASHED FILESYSTEM πΊπ¦ last edited by