5 ms·
I am just saying that the function has merit. Even if it could have been written much better. Thats all :-) It served me well. Reg downsides: Maybe don't use i
by mpfundstein 6y ago
I am just saying that the function has merit. Even if it could have been written much better. Thats all :-) It served me well.
Reg downsides: Maybe don't use it on a directory with 1000 entries...? Its good to be aware of that or not?
- boring_twenties 6y agoSo just what the fuck are you supposed to use on a directory with 1000 entries?
- icholy 6y agoYou can drop down into the lower level apis https://godoc.org/golang.org/x/sys/unix https://godoc.org/golang.org/x/sys/unix
- doteka 6y agoYeah, nope. There are many appropriate levels of abstraction in between “do this the dumbest way possible” and “write raw unix syscalls using a library outside of the standard distribution”.
- icholy 6y agoJust because something doesn't work for your use-case doesn't make it the "dumbest way possible". It just makes you sound dumb.
- doteka 6y agoNo, this is literally the dumbest way possible to accomplish the task. It is as close to a brute force approach as you can get, I can see no way in which it could be less efficient without being malicious. And it is the only way of accomplishing this task in the standard library of a language which prides itself on performance and maintainability. 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.
- icholy 6y agoThere's https://golang.org/pkg/os/#File.Readdir https://golang.org/pkg/os/#File.Readdir
- Someone 6y agoWhich, as far as I can tell (couldn’t find opendir/closedir), has the same problem. I think they named the call after the posix one. If so, they must have known about opendir/closedir.
- icholy 6y agoIt uses https://golang.org/pkg/syscall/#ReadDirent https://golang.org/pkg/syscall/#ReadDirent and https://golang.org/pkg/syscall/#ParseDirent https://golang.org/pkg/syscall/#ParseDirent to incrementally read them.
- boring_twenties 6y agoThat interface is just awful, here's a byte buffer and some offsets, good luck.
- hu3 6y agohttps://github.com/karrick/godirwalk https://github.com/karrick/godirwalk
- doteka 6y agoLet’s not do participation trophies though, Pike and Thompson were the original authors of Go. Both of them should know better. 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...
- deleted 6y ago[deleted]