4 ms·
I prefer explicit blocks for automatic object destruction to RAII. For example, withThing { thing => doStuffWith(thing) } This makes it clear to me that the
by norir 3y ago
I prefer explicit blocks for automatic object destruction to RAII. For example,
withThing { thing => doStuffWith(thing) }
This makes it clear to me that the object is only valid within this block. There is no copy constructor madness where I might completely lose track of where the object might be alive and in scope.
- vacuity 3y agoNote that C++'s design of RAII and Rust's design have important differences.
- jjnoakes 3y agoThe problem with blocks is that you can forget them.
- fl0ki 3y agoRust does keep track of where the object is alive and in scope, even if that happens to be decided dynamically, e.g. an object may only exist in a condition branch or as the result of a loop running at least once. Objects also won't be silently copied unless they are types that explicitly marked as trivial to copy (i.e. bytewise). It then also guarantees cleanup if the object actually does exist. Rust already does what many people want for deterministic, safe cleanup, which like C++ includes RAII, but unlike C++ is not limited to RAII.