Golang 1.4 Internal Packages
golang.org
golang.org
I do note that the Go-centric world would naturally make the file system part of the language. Its plan9 heritage makes this very easy.
I also note that this is a mistake in language design. Packages and modules should never be reliant under an assumption about the underlying file system, as it tend to lock languages to certain platforms.
And it gives you an escape hatch from Java-style module nonsense: of COURSE I want to traverse 7 singleton directories to get to the source code!
But of COURSE, it is so modern to blame Java for everything these days.
e.g instead of com/foobar/bar/module/a/b allow com.foobar.bar.module/a/b
It's only when you try to run the thing that the JVM will complain (with the rather unhelpful error message "wrong name: x/y/z/Foo"). So if your build process builds the correct folders and stores the .class files there, it's going to work. (Not that it's very useful; after all, your build system would have to know where to put everything.)
The only assumption here is that the filesystem supports a tree.
† This means any current filesystem except FAT which has (had?) a habit of changing the case of same-cap names in one way or the other. Cap-changing renames are a chore on some systems though.
They are not. Import paths are not part of the language, they are interpreted by the go tool. The only relation to the filesystem is that by using the go tool, you will get a directory hierarchy that seems to match import paths in the sense that that in foo/bar you will have a bar directory child to a foo directory. This is very useful to developers, it means they can find their files, but you could build a conforming build tool that keeps files in SQL, if that's your thing.
The proposed changes are onerous because integrating with the toolchain to enable this feature requires changes to source code.
Moreover, the proposed change is so very tied to a specific toolchain feature that it is likely that as the Go team encounters new package dependency management issues that they will continue to propose these micro tweaks to package import paths which require the rest of us to run around touching every source file.
If you're talking about using this feature with existing code, renaming a directory is not a hard operation.
The Go team has decided to interpret that as an opportunity to interpret these tokens as an expression language with the following capabilities: locate packages on the filesystem, locate packages from some specific version control systems, (proposed) control how packages are compiled.
My beef with this change is two-fold. First, why is there no specification for the package import path when there is plain, obvious, and necessary information encoded in this opaque token. Second, why is expediency a good justification for including compiler control flags in this undefined, unspecified opaque token.
If the package import path is going to be used like this, then it should be standardized in the language specification.
Expediency is not used as a justification for this at all. You're wrong that any compiler control flags get involved here; 6g is going to be invoked with exactly the same syntax, and doesn't get told anything about "internal", just as it isn't told anything about build tags, or OS/arch-specific filename control (e.g. foo_linux.go).
AFAIK this also introduces the English language into the currently freeform world of user import paths. I guess source files themselves already have something similar with the "_test.go" suffix, so there's some consistency with that.
The main proposal is one of scoping by directory hierarchy - /a/b/c can import a/b/d but a/g/x can't.
No - x can import d because d isn't in a directory literally named internal. That's the magic name.
"internal"
> The main proposal is one of scoping by directory hierarchy - /a/b/c can import a/b/d but a/g/x can't.
/a/b/c can import a/b/d, and /a/g/x and /z can too. The new rule is that /a/g/x can not import /a/internal/y.
As I understand it, /a/g/x CAN import /a/internal/y, because /a/g/x is in the directory tree that starts at /a/. However, /b/h/z CANNOT import /a/internal/y/ (while previously, it could).
What ML modules have as extra advantage over other module systems, is that they also exist as types.
This is so basic and has been solved by other languages so long ago that it's quite strange to see Go had to reach 1.4, and 5+ years of age to get this...
...and in quite an ad-hoc and hackish way -- which means you're tied to a directory hierarchy.
As the quote (attributed to Einstein IIRC) goes: "You must strive to make things as simple as possible -- but no simpler than that".
This is, I think, something "simpler" than simple ("simpleton"?).
The Java approach for standard packages is nearly identical to what's proposed for Go. Anything in the com.sun. (or whatever they call it now) namespace is considered internal, even though it's publically accessible.
[0] https://groups.google.com/forum/#!topic/golang-dev/_cAggq73y...
As in "without deep thought", "ho-hum" and 30 years below the state of the art?
That said, transforming the package import path into a half-assed file system query language slash dependency management solution is a source of frustration for a problem that has been elegantly solved by DNS.
I would love if the Go team redefined package import paths as strings to be resolved by go-dns -- an imaginary package name resolution tool which looks up package imports by resolving paths via records stored in package, workspace, and upstream "nameservers".
Or, you know, use Godeps.
GOPATH=`pwd`:$GOPATH go build $1.go
...where my bash_profile initially exports GOPATH as /usr/local/go. Probably unconventional but hey, it works.