2

The usage of quotes in Go's import statement strikes me as unnecessary. Typical Go import statements look like:

import "foo/bar"
import other_name "foo/bar"
import (
    "foo/bar"
    x "foo/baz/bar"
)

According to this Quora post, it's for unusual paths containing weird characters.

As far as I can tell:

It strikes me as an unusual concession to make - how often does one see import/includes using paths with spaces or other weird characters? What was the original reason behind requiring quoted paths? Is it documented anywhere?

  • 2
    I'd guess that it's because you can include urls in them – Daenyth Jan 14 '16 at 18:00
5

I don't know if they're a core golang dev, but Aram Hăvărneanu answered this question here:

The structure of an import path is not part of the language specification, so it has to be a string [...] to allow flexibility and to avoid locking in some semantics forever.

I agree with you: I think the majority of programmers won't need those non-standard paths and Aram's justification smells of YAGNI. Sure, support for some alternative import or "weird paths" might be nice, but it should be optional, without forcing this ugliness upon everyone.

  • Aram's prudence seems sensible to me. Only the golang team knows precisely what their costs are, and maintaining something as part of the language specification does carry a cost. – Robert Harvey Jan 15 '16 at 17:27
  • Another factor could be that afaik, Go was developed for Google's server needs. Maybe they needed the custom imports, with their distributed architectures and whatnot? – uryga Jan 15 '16 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.