include - Are the following assertions about Go packages accurate? -


are following assertions go packages accurate?

  1. import "package_name" imports files directory called package_name assuming found in $gopath, variable holds users go directory, or in standard go installation directory tree.

  2. files within package_name directory state package package_name. not required to. in fact, import "package_name", import file including line package foo if file found in imported package_name directory.

  3. all functions capitalized accessed through name given in package package_name declaration--for instance:

package_name.function_in_file_that_declares_package_name or other_than_package_name.function_in_file_that_declares_other_than_package_name

  1. user defined packages command-line go install-ed within package directory. however, go refuse install directory named identically builtin package directories. instance cannot install strings directory since go has strings directory builtin package "strings." however, user can append functions strings package without altering builtin strings folder, creating my_strings directory , placing file states package strings within it. now, import my_strings load user-defined strings functions accessed strings.function_name.

in summary, import keyword used load files given directory. , keyword package creates namespace access capitalized functions outside file.

am understanding of above correctly?

  1. the argument of "import" import_path, not package name. makes exported entities package found in $gopath/src/import_path available in file scope "import" clause appears.

  2. all *.go files, except *_test.go files , files // +build ignore, in single directory must same name in package name clause or go build system reject it.

  3. not capitalized, belonging unicode category lu. not functions tld entity.

  4. no, can go-install package directory using import path. yes, packages stdlib have priority , cannot "overriden". however, can "replace" stdlib package using eg. import strings "github.com/foo/mystrings". however, effect local/file only.

in summary, no, import used make entities other packages available in file scope. keyword "package" creates no namespace. effect of "import" file-scoped, see preceding sentence , imported entities referred qualified names. qualifier sort of namespace, note not "exporter" (package foo) controls that. instead control @ "importer" side: import whatever_local_name "whatever_import_path". default qualifier basename of import path, though.

"do agree?"

not @ all.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -