In the Go programming language, why after importing a package do I still have to prefix a method within that package with the package name?
i.e.
import "io/ioutil"
func main() {
content, err = iotuil.ReadFile("somefile.txt")
// etc..
}
Isn’t this redundant? In Java, for example, you can do things like importing Files.readAllLines etc without having Files imported.
I guess this doesn’t really answer your question, but if you want, you can actually call the methods without explicitly stating the package – just import with a
.in front of the names (but this is not recommended; see below):Note @jimt’s comment below – this practice is not advised outside of tests as it could cause name conflicts with future releases. Also, definitely agree with @DavidGrayson’s point of being nicer to read/see where things come from.