-
Notifications
You must be signed in to change notification settings - Fork 18k
go/doc: limit factory functions to only ones starting with New #28006
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
Is that what you are proposing ? Then it should be a proposal, rather than a bug. |
It is more a small improvement than a formal proposal. |
Re-titled appropriately. |
|
Yes, |
That's clear, but you've missed the point of my objection: fixing false positives comes at the cost of new false negatives that exist for a long time, for example here. Also, wrt #27812 (comment), why shouldn't |
I don't know, it is my intuition that |
What about |
I think this is overly restrictive. There's plenty of proper factory functions that don't start with New. Personally, I use NewX for functions that create a new X that is a pointer, and sometimes MakeX for a new X that is not a pointer. @dominikh mentioned a few other patterns as well. The original go/doc heuristic has worked mostly well. The more recent fine-tuning (exclude functions that return more than one type from the list of factory methods) probably overshot a bit into the other direction. We should correct that one, instead. For instance, a final error result should not be considered as an additional type in the decision making. If there's types in a result that are not declared in the current package, we may want to eliminate those functions as well. There's some fine-tuning we can do that should get as 99% there w/o the need to restrict names. I'm leaning against this proposal. |
how about only view the functions with a Camel-Case style name and the last segment in the Camel-Case name is the same as the base type of a type as the constructors of the type? |
See the |
OK, so it looks it hard to make a perfect solution for both sides. Closed. |
Please answer these questions before submitting your issue. Thanks!
@rsc suggest to open a new issue, so this one.
What version of Go are you using (
go version
)?go version go1.11.1 linux/amd64
Does this issue reproduce with the latest release?
yes
What did you do?
Open https://golang.org/pkg/net/http/, and search the Post and Get functions.
What did you expect to see?
The two functions should be listed at the beginning part, package-level functions zone, of the doc.
What did you see instead?
The two functions are listed under the type Response zone as constructors, which is undesired.
Maybe we should limit constructor functions to the ones start with "New".
The text was updated successfully, but these errors were encountered: