logoalt Hacker News

kaashifyesterday at 10:36 PM1 replyview on HN

If the idea of computers is that they remember stuff for you and do stuff for you, then both try/finally and defer seem like hacks to work around not having RAII like e.g. Rust or C++ where resources are closed/disposed of/deallocated automatically.

Try X finally dispose of all resources. X, defer clean up X. Or how about just X and cleanup is done automatically, with the author of the resources deciding what is needed to clean X up.


Replies

mcintyre1994yesterday at 10:50 PM

JS has the using keyword for this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

show 1 reply