You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an "unwritten convention" in Go whereby the last element of the import path should be the same as the name of the package, although nothing forbids this from happening:
package hello // import "howl.moe/goodbye"
Users of the package will then have hello as the "default" identifier for that package, unless overridden in the import:
package main
import (
"howl.moe/goodbye"// this will use identifier "hello"
goodbye "howl.moe/goodbye"// this will use "goodbye"
)
I think this has caused reasonable confusion in the past, and adds a layer of complexity when parsing the source code. As such, I propose restricting adding packages to the chain only if the identifier in the package clause matches the last slash-separated element of the import path, ie. goodbye for howl.moe/goodbye.
While I don't think there is a strong argument to be made about including this in the language/VM itself (it would mean that the code parsing is aware of the import path, which shouldn't necessarily be the case), I think it makes sense to have this as a restriction for addpkg. This way we can, as human readers, be sure that the identifier for imported packages will match the last item of the import path.
Upgrade concerns
See-also #694 for a discussion on upgrading packages and realms.
The canonical way to have a v2 import path in Go is the following: github.com/my/import/path/v2. Under this restriction, the package identifier should be v2. To overcome this, I propose two alternatives:
Correctly handle /v[1-9][0-9]* suffixes as a special case.
Use a different "version syntax" altogether, such as gno.land/my/import/path@2.
The text was updated successfully, but these errors were encountered:
There is an "unwritten convention" in Go whereby the last element of the import path should be the same as the name of the package, although nothing forbids this from happening:
Users of the package will then have
hello
as the "default" identifier for that package, unless overridden in the import:I think this has caused reasonable confusion in the past, and adds a layer of complexity when parsing the source code. As such, I propose restricting adding packages to the chain only if the identifier in the
package
clause matches the last slash-separated element of the import path, ie.goodbye
forhowl.moe/goodbye
.While I don't think there is a strong argument to be made about including this in the language/VM itself (it would mean that the code parsing is aware of the import path, which shouldn't necessarily be the case), I think it makes sense to have this as a restriction for
addpkg
. This way we can, as human readers, be sure that the identifier for imported packages will match the last item of the import path.Upgrade concerns
See-also #694 for a discussion on upgrading packages and realms.
The canonical way to have a v2 import path in Go is the following:
github.com/my/import/path/v2
. Under this restriction, the package identifier should bev2
. To overcome this, I propose two alternatives:/v[1-9][0-9]*
suffixes as a special case.gno.land/my/import/path@2
.The text was updated successfully, but these errors were encountered: