just use it when you need it and be aware of the downsides...
just use it when you need it and be aware of the downsides...
Creating an API where the entire set of data is returned from a data source, without an option to limit the result, is bad. It means that, if I have to read a directory with 2000 files (and this is quite possible! - think /bin, etc.) the function will have to allocate a slice with 2000 entries, and then call stat on all of them.
Stat is not free, especially on certain filesystems (NFS!), nor is reading directory entries.
It's a mega convenient function if you want to slurp in a few files.
What does being aware of the downsides get you?
Is there some alternate interface that avoids the downsides?
Reg downsides: Maybe don't use it on a directory with 1000 entries...? Its good to be aware of that or not?
Also, thanks for the ad hominem, perhaps you shouldn’t attach your self worth to a programming language and see how that works out for you.
I think they named the call after the posix one. If so, they must have known about opendir/closedir.
It’s fine to include an inefficient version if you also have a ‘proper’ way to fall back to when performance does matter. And if performance does not matter, why are you even using Go? Funnily enough Python Ruby and Node do expose performant ways to do this in the stdlib, so...
You opendir, read 100 entries, do whatever with them, read 100 more, repeat, then closedir. So it's a buffered interface similar to normal I/O.
There's been proposals for doing readdir+stat in one syscall, but nothing merged yet. https://lwn.net/Articles/606995/