Why does code in a package use "using" and "import"?

Not telling anything new, but this way of explaining it helps me understand better:

  • About importing and using modules:

    • using Foo brings the module Foo and its exported objects into scope.
    • import Foo brings the module Foo into scope, and nothing else.
  • About importing and using objects from a module:

    • using Foo: x, y brings x, y from module Foo into scope, but not the module Foo itself or other objects from it.
    • import Foo: x, y (or import Foo.x, Foo.y) does the same, but if x or y are functions, they’ll be available for method extension in the current scope.
  • Additionally, all functions from a given module are always available for method extension in their module’s scope. So, if the module Foo has been brought into scope of module Bar (with using or import), its functions can be extended in the code of Bar referring to them as Foo.x, etc.

16 Likes