4 ms·
I've been writing some C# lately and `using` has been very nice to use with file handles, buffers, etc., that might need to be cleaned up. But they only work ni
by maxfurman 3y ago
I've been writing some C# lately and `using` has been very nice to use with file handles, buffers, etc., that might need to be cleaned up. But they only work nicely in C# because the C# stdlib has properly implemented `Dispose()` for File, StreamReader, et. al. Whenever I'm dealing with library types I have no idea if I'm supposed to dispose of them or not. We've got a similar problem here with JS where the node team has to implement `[Symbol.dispose]` in all the relevant classes (ugh) and who knows when that will land. And until then the runtime has to clean up disposable resources without the help of `using`. So what's the point?
- mattmanser 3y agoBecause at some point it will be better. Typescript is strongly typed too so I assume it won't let you use using on things that don't support it.
- mmis1000 3y agoThese arguments can be also applied to promise and await. And they almost ultimately won these days. Sure, you need to implement the then function or whatever properly or it won't play nicely with code other wrote. But once enough people adopted it, it's almost no way to go back. If you are a big library author and you don't bother to, probably other will just write a wrapper(request-promise for example) or make a clone with that buildin(there are so many and it's pointless to count). It's FOSS anyway.
- maxfurman 3y agoYou can await values that aren't already async in JS. IIRC the runtime turns it into the equivalent of `await Promise.resolve(x)`.
- Jochim 3y agoMy experience in C# has been that almost all library types that require resources to be released will implement the same IDisposable interface provided by the System namespace. I'm sure there are examples of libraries that don't do this but I can't think of any off the top of my head and I'd assume that they're fairly rare.