-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/vet: add vet check for shadowing builtins. #40899
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
Hi, this is pretty much #38832 (proposal: cmd/vet: Should check for assignments to inbuilt types).
This would make the check pretty much useless, IMO. I'd bet that this kind accidental shadowing happens mostly on variable assignments inside functions, e.g. someone writes Closing here in favour of the older thread at #38832 (feel free to post your idea about a reduced check only on function signatures there, if you wish, so we can keep all the discussion in one place). |
@ALTree If there's some reason I don't know of that justifies this, I'd love to hear it, but I can't really think of anything that would. |
We try to keep all discussion in one place. That doesn't mean we succeed in that attempt. It's especially hard because someone can start a new discussion about the same topic at any time. And when they are told that they should move the discussion to a place where it is already happening, they often don't. Deciding whether something is the same issue or a different issue is a difficult problem. We'll get it wrong sometimes. Often there isn't enough information to be sure, so we recommend people open new issues with more information. Only after more information is forthcoming will we realize for sure that it is in fact a duplicate or close enough that discussion should move to a previous issue. |
@randall77 I see how it is a difficult problem, but what you are asking me to do won't help. How am I supposed to reply to the points @ALTree made? am I supposed to go into this other thread, and start talking about a comment on a different issue, do I have to repost my proposal as a comment? Also, as far as I can tell, nothing about this is mentioned in
|
Yes. Repost your proposal as a comment. Maybe "hey, maybe we just do this at global scope instead of in function bodies. ..."
I agree. But don't think #38832 is highly active. It has 10 comments currently.
I also agree. @ALTree did the search for you and found the issue, then pointed you to it.
True, but that just makes the github-lack-of-threading problem even worse.
We don't want more discussion that just repeats previously-had discussion. That's the main reason we want to keep discussion in a single issue, so that it's easy(-ish) to peruse, and not repeat, what has already been discussed. |
The goal of keeping the discussion about a specific problem all in one place is to be sure that the people vetting the proposals and making decisions about them don't have to keep seeing (and reading) the same thing again and again and again. While it's true the your proposal and the one in #38832 would flag different code, the core of the matter is the same: "should In general, if something needs to be investigated (and decided upon) only one time, then we try to have one discussion about it; unless the issue at hand is so complex and multifaceted that discussing it in one place is literally impossible. |
Go allows you to "shadow" (define a function with the same name as) builtin functions. As I understand, this for backward compatibility, allowing new builtins to be defined without breaking existing functions. This makes sense.
However, shadowing builtin functions, especially at the global scope, is generally bad. Due to go's lack of methods on builtin types (and as of now, generics), it has a few builtin functions that are rarely used, and easily forgotten or never learned about by novice programmers (e.g.
copy
anddelete
). Because of this, someone could inadvertently redefine a builtin without knowing it. They could then realize they needed that builtin, and have to go back and change everywhere they used the function that was shadowing it to a new name.Because of
go vet
's high requirements for accuracy (i.e. lack of false positives), This rule should probably only check global function declarations (this also helps with performance, requiring less ast traversal).The text was updated successfully, but these errors were encountered: