Hacker News
points by GuB-42 1 day ago | 0 comments
It is like saying "why do C++/Rust people don't want a garbage collector?", or "why do Haskell people insist on function purity?". A GC in C++ and Rust would make things much easier, and a few impure functions would likely make Haskell more practical, and then, if Rust let go of all that "memory safety" cruft, it would be much easier to write one-off scripts and prototypes with it.

Languages have opinions, that's why there are several of them and they are popular in some applications and not others. And Zig opinion is to be explicit so RAII is out, and the language does push you into avoiding allocation when unnecessary, as a side effect of not giving you the "easy to use interface" you want.

This makes it particularly suitable for fields like embedded software where you may not have malloc/free at all, but may be less so in a highly dynamic environment, where you may be better served with a GC anyways.

[–] silon42 1 day ago
You could easily have explicit RAAI... the compiler just needs to complain until you write all drop(x) explicitly. Maybe an idea for future of Zig.
[–] GuB-42 1 day ago
To me, that's not RAII, it is static analysis, useful, but different.

To me, the name "Resource Acquisition Is Initialization" implies that doing one means the other one is done implicitly. Now, in the end of the day, the result is machine language, with proper discipline you can follow the RAII principles in any languages, including assembly, but I have always understood RAII as being it done implicitly.

Also we can argue that Zig supports a weak form of RAII through the use of "defer", there are some nuances here.