Re:Rust RAII is better than the Haskell bracket pattern
by pcwalton on Tuesday October 09, 2018 @01:28PM
(#18177970)
The alternative to closing the file in the destructor is leaking OS resources in the event of unexpected control flow destroying the file object. I fail to see how that is preferable.
[ Parent
| on HN ]
Re:Rust RAII is better than the Haskell bracket pattern
by masklinn on Tuesday October 09, 2018 @02:14PM
(#18178409)
A linear resource would require that the resource is explicitly released on all codepaths no?
Re:Rust RAII is better than the Haskell bracket pattern
by pcwalton on Tuesday October 09, 2018 @02:21PM
(#18178474)
Not in Rust, and not in any language where you can put resources in objects with shared ownership (i.e. any remotely popular general purpose language).
Throwing exceptions isn't a particularly good solution either, for the same reason. Exceptions are hard to reliably handle when you can't easily reason about where they will be thrown from.