3 ms·
Quite a useful change at first glance, equivalent to go’s `defer`? If you use react, it can get a lot more interesting[0] [0] https://twitter.com/JLarky/statu
by Karupan 3y ago
Quite a useful change at first glance, equivalent to go’s `defer`?
If you use react, it can get a lot more interesting[0]
[0] https://twitter.com/JLarky/status/1669741878324113408 https://twitter.com/JLarky/status/1669741878324113408
- iainmerrick 3y agoIt's not really the same as defer. If you're working with a file, you have to "open" and "defer close" separately. The point of "using" is to combine those into one statement -- it's more like RAII.
- Karupan 3y agoTrue, “equivalent” was the wrong word to use.
- masklinn 3y agoIt's not really like RAII either, because you have to `using` the object. It's a closer cousin of Python's context manager (aka C#'s using statement — probably where it actually comes from — and Java's try-with-resource), which probably hew closer to Common Lisp's unwind-protect (that is not type-oriented, but usually you'd create your own macro around that).
- iainmerrick 3y agoYou’re right, but I don’t see a big difference in practice if the compiler is able to check that you’re using “using” correctly! Hopefully there’s at least a warning if you call something that returns a disposable object, but don’t dispose of it.