-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/go: reserve example/ and test/ as non-stdlib path prefixes #37641
Comments
Wouldn't I'm overall in favor of this proposal. I seem to recall that @rogpeppe uses From the tooling perspective, these rules are easy to implement, so that doesn't worry me either. The rules should be well documented, though, and probably alongside #32819. Do you reckon that any sort of API would be useful for tools here? Similar to https://golang.org/pkg/go/token/#IsKeyword, imagine something like |
Maybe? I'd be fine with omitting it from the reserved names. |
Maybe? I'm not sure who would use them, though: I don't think we should explicitly reject other dotless paths at this point (we can break them if/when we need the name for something else, but if users are confident we'll never use their name I see little harm in letting it persist). I guess it could be useful for linters..? |
( |
I'll point out a cost of implementing this change, since I don't see it mentioned here so far, is that this will increase the amount of special cases. Special cases need to be documented, taught and learned by all Go users. Users who are not aware of the special cases and run into them accidentally may be surprised. I think it's a good idea to evaluate how often each special case is expected to be used. For example, the package name |
What would it mean to reserve these paths? I'm guessing a documented promise to never create Should we allow dotless paths using reserved prefixes in the |
Yep. Specifically, we would apply the Go 1 compatibility policy to the non-existence of these paths in |
Not at this time. (We could consider it as a future change, but since these paths explicitly do not have a single source of truth, I don't think they'd be a good fit.) |
What about jusing using |
@slrz What you're suggesting is already possible, it does need any work to be completed. Or are you suggesting that as a reason this proposal should not be accepted? |
@slrz, IANA made the dubious decision to host an actual server on https://example.com. While I do use those domains in examples myself, I could reasonably understand someone wanting to avoid them on security grounds: if those servers are ever compromised, they could serve |
Please leave reserve |
@bronze1man, |
Hi @bcmills, overall, I like the proposal. Do you think the main use cases could be addressed by picking just one? For example, maybe just pick People could still then use hierarchy underneath |
@thepudds, just For example, an “example” module in a tutorial is not really “local”. Someone following the tutorial might not understand |
Hi @bcmills, I like the proposal.
|
Just as a data point, I often use
If prefixes were to be reserved, I'd echo @dmitshur's reflection that these special cases would need to be documented, and having many special cases increase the learning cost. As such having a very clear rule, e.g. |
Let's officially reserve Let's not do the single-letter thing. It's fine for us to do that ourselves, For things that need a long-term guarantee, it is reasonable to ask people to I don't understand the need for local, or else I disagree that it's a good use. |
Are there any objections to "Let's officially reserve example and test and stop there."? /cc @bcmills |
Reserving @rsc one that you didn't include and didn't mention why is I have to admit that |
|
I'm open to being overruled on this, and I don't think this is a very significant change either way, but I would object at this moment because based on my evaluation of this proposal, the value it adds is too low compared to the cost of introducing this change. The advantages of going with the suggested resolution, as I currently perceive, include:
The costs of going with the suggested resolution, as I currently perceive, include:
I think there would be a much stronger need for this proposal if the reserved TLDs ¹ https://tools.ietf.org/html/rfc2606#section-2 Edit: I want to clarify that I have considered this point:
I think the proposed solution would benefit a small number of users by a small amount, and incur a small cost on a very large number of users. Because the benefit is so small, the left hand side of the equation doesn't seem to outweigh the right hand side by my current estimates. |
My main hesitation about depending on the TLDs is that example.com was supposed to be the reserved name, and yet example.com has a web page. That means that go module examples using example.com make HTTPS requests. I don't trust the IETF not to create web pages for the other "reserved" TLDs. The only thing we promise by reserving example/ and test/ is that we will never create those two directories in $GOROOT/src/. That is, there will never be a standard library package named example or example/x or test or test/x. |
Perhaps you meant this implicitly, but I think there should also be a test (or equivalent automated mechanism) that would detect if a future CL accidentally forgets about this promise. We shouldn't rely only on human reviewers for this. |
See golang/go#37641, which was accepted a few months ago. Packages like internal/foo are also somewhat common, and we can know for sure that they don't belong in the standard library, as they couldn't be imported then. Updates #38.
given that these are reserved names, should a better error be returned? compare
|
Sorry, this is a bit late, but I presume "local" would behave the same as " |
Change https://golang.org/cl/359594 mentions this issue: |
Change https://golang.org/cl/359576 mentions this issue: |
The
go
command automatically fetches modules from network hosts, provided that those modules have a path whose first element includes a dot character (.
).First-elements that do not include a dot are, in general, reserved for the standard library and the Go toolchain (see #32819). Some names (
std
,cmd
,all
) have a special meaning no matter where they are used. Others (such asarchive
anddebug
) are currently standard-library prefixes but not packages, but could be made so in the future (as was done in the case ofencoding
).Still others currently have no meaning, but may be assigned a special meaning in the future: for example, I would like to add
mod
to refer to the main module independent of its path (that would be a separate proposal).The fact that import paths are required to contain a dot occasionally causes user consternation (#37554, #34592).
I propose that we explicitly reserve the following package paths for user code:
local
localhost
, which we may at some point want to treat as a hostname.example
(along the lines ofexample.com
, because it looks more like “something you should replace” thanlocal
does)test
, which we already sort-of use:go/test/bench/go1/go.mod
Line 1 in b1a783d
main
(because it is useful to indicate "the main module", and apackage main
is not importable anyway), andcmd/go
tests.CC @bronze1man @DisposaBoy @mvdan @jayconrod @matloob @thepudds
The text was updated successfully, but these errors were encountered: