18 ms·
Nah. Why does the caller have to figure out how to dispose? Let the callee say how to do that. let connection = getConnection() defer connection.disp
by paulddraper 3y ago
Nah.
Why does the caller have to figure out how to dispose?
Let the callee say how to do that.
let connection = getConnection()
defer connection.dispose() # dispose? close? finalize? quit?
vs
await using connection = getConnection();
Same with C++ RAII.
Connection connection();
- konart 3y ago>Why does the caller have to figure out how to dispose? Rather than how the caller have to figure out when to dispose. Defer\using will wait till we out of scope or till we return. While it may be much better to close\dispose as soon as possible or after some event.
- mmis1000 3y agoYep, this merges countless of way to dispose a resource into a single interface. Like what promise did to callback functions. (And promise almost take over plain callback these days) Even you don't use the 'using' sugar. You may still be benefited from it if you need to implement some sort of resource management someday. Instead of write a tear down function for every single type of resource in your code. Probably everyone will just agree upon that `Object[Symbol.dispose]()` will free this resource. And you only need to do it once and for all.
- pavlov 3y agoI sort of keep expecting we'll eventually have C++ where it's just: Connection. ...and it gives you an instance in a local variable with the lowercase initial to match the type. Like the "Churchill Martini" where he — according to legend — asked the bartender to pour the glass full of gin, and then he'd nod at the vermouth bottle on the shelf and say "Vermouth."