-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: path/filepath: Deprecate Walk #69604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Define 'deprecate'. |
I'm not sure it's useful to deprecate a function that doesn't have an exact equivalent that people can simply switch to. The docs for |
Add |
In most cases, the DirEntry is sufficient. If it’s not, you can just do a .FileInfo() call yourself at no loss of efficiency. Or just keep using Walk because it’s not going to be removed. |
Yes, you can update, but the update can't be easily done mechanically, and I don't think the performance advantage here is sufficient reason to push people to modify existing working code. I think what you are looking for is something more like "hint when writing new code that a different choice would be better". Our current uses of deprecation apply to existing code as well. As far as I know we don't have that kind of hint at present. |
I don't think the expectation is that there's always a trivial find-and-replace for deprecations. For example, My expectation is that a large percentage of the changes from Walk to WalkDir would just need to change from fs.FileInfo to fs.DirEntry in the callback, but the ones that need more than that are fairly easy to catch and fix when the type check fails. I think it actually could be done mechanically with a type aware rewrite tool. |
I'm not sure it's quite analogous.
To be clear I certainly agree that new code should use |
Rather than marking a function as deprecated, I'd like "go vet" or gopls to give me some hints like "WalkDir performs better, you should use this" or something like that. And if you add this hint, the same thing should be applied to |
The comments already say that. Go vet's guildelines (see the README) have no scope to do suggest faster code. Whether gopls's job includes repeating all the information in the comments is up to its authors. I don't believe it does, though. |
Reading the discussion so far, I agree that it seems like the most ideal answer here would be a new classification that is softer than "deprecated" but still machine-readable so that tools can react to it. However, I also have a feeling that discussing such a thing here is taking the issue off-topic. 🤔 At the risk of straying further off-topic 😬 ... The idea of this being a Of course that's not an answer for everyone, but I will admit that when I'm writing new code I do tend to "follow my nose" by selecting the most likely candidate from the code completion list, rather than carefully reviewing the documentation for each function. Having |
I think as above, Deprecation is too strong for filepath.Walk. |
Proposal Details
filepath.WalkDir was added in Go 1.16. It's past time to go ahead and deprecate filepath.Walk, which is less efficient.
The text was updated successfully, but these errors were encountered: