3 ms·
> But in all seriousness, this advice is applying a notably higher standard of premature optimization to file descriptors than to any other kind of resource. M
by lmm 6y ago
> But in all seriousness, this advice is applying a notably higher standard of premature optimization to file descriptors than to any other kind of resource.
Maybe the same standard should be applied to other kinds of resources. Maybe garbage collection was a mistake.
> It's a violation of procedural abstraction to know whether the result of load is lazily evaluated or not; it's just supposed to implement an interface.
Lazily-loaded things are different from eagerly loaded things in important ways. If it's not possible to make that distinction visible in your language, get a better language.
> No, it will not be fixed. This version only appears to work by not closing the file until the generator is exhausted or collected.
Which is exactly what we wanted. It is fixed.
> Furthermore it demonstrates that often the context is not being managed locally. If a file object is passed another function, then it's being used outside of the context. Let's revisit the json version, which works because the file is fully read. Doesn't a json parser have some expensive parsing to do after it's read the file? It might even throw an error. And isn't it be desirable, trivial, and likely that the implementation releases interest in the file as soon as possible?
Look at iteratees for the full solution to this problem. Managing context can be hard, but it doesn't have to be; you just have to use the right abstractions.
> Those threads are essentially debating whether a resource pool is "leaking" resources.
If you open a pool and never close it, of course you're leaking everything in that pool.
> if all this orphaned file descriptor paranoia was well-founded, it would have been a problem back then too.
It was. Long-running python programs broke because they ran out of file descriptors.