The necessity of having package names in a code when the package was declared in import

There definitevly was a reason for having package names in code after those packages were declared in an import block. Let’s explore the following code snippet. The second (commented) variant seems easier.

  • it’s shorter and faster to write it down
  • there is no confusion about what is actually the Appliances - an object or a package

So why had this pattern chosen when the language have been formed?

    package main

    import (

    func main() {
        myAppliance, err := Appliances.CreateAppliance()
        //myAppliance, err := CreateAppliance()

If at least two of the imported packages have a function Foo which one would you pick if everything is imported unqualified?

If though you want to pollute your local packages namespace you can import (. "fmt").

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.