Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

100% Positive

Analyzed from 178 words in the discussion.

Trending Topics

#try#resources#finally#defer#remember#dispose#forget#around#stuff#raii

Discussion (4 Comments)Read Original on HackerNews

throwaway81523•about 2 hours ago
Article describes try/finally as a hack to get the effect of defer, but it looks to me like it's the other way around? Try/finally is more traditional, in one form or another.
Rohansi•about 2 hours ago
It's also necessary here because TypeScript has exceptions and you'd expect your `defer`s to execute even when an exception is thrown.
kaashif•about 1 hour ago
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.

mcintyre1994•about 1 hour ago
kaashif•9 minutes ago
What if you forget to use that and just use let or const? It is better than plain try-finally or defer because you don't have to remember how to dispose of the resources but in terms of remember to dispose of the resource at all, I don't think that is all that different from Python's with or Java's try-with-resources. You can just forget to use using, with, try-with-resources.

There isn't any way to forget to drop a resource if you have RAII.