Remix.run Logo
okigan a day ago

that's a very broken metaphor - it might be "similar" to try-finally block if you only have one variable/object following RAII. But try-finally block(s) become complete mess when multiple variables are involved, and again requires way more typing/duplication than RIAA. And "similar" in terms of results, NOT similar in terms of performance as try {} block requires additional instructions to set it up, whereas RIAA is runtime free.

And regarding sibling post about finalizers -- another broken concept as you cant use finalizers with limited resources (ex. graphic contexts, db connections, handles, locks, etc) and then these languages that use finalizers become complete mess if you need to manage such resources.

Rohansi a day ago | parent [-]

> And "similar" in terms of results, NOT similar in terms of performance as try {} block requires additional instructions to set it up, whereas RIAA is runtime free.

By similar I meant from the compiler's point of view. `try...finally` is the low level primitive to ensure some code runs at exit. If something throws an exception then destructors must run when unwinding the stack, which is what `finally` is for! But if you disable exceptions then `try` blocks are probably all basically no-ops.