Re: Reworking import statements (proposal)

Naftoli Gugenheim <[email protected]> Thu, 14 Apr 2016 05:06:48 +0000
Newsgroups gmane.comp.lang.scala
Message-ID <CANpg8PAWU1USTU7VhPi5mmjOiSdMJFWr-Rqe-nVxHuFQWWseCw@mail.gmail.com>
On Wed, Apr 13, 2016, 7:02 AM Piotr Tarsa <[email protected]> wrote:

> Hi,
>
> As of now relative imports (ie importing from something already imported)
> look exactly the same as absolute ones (ie where we're importing using full
> paths), except when explicitly starting from _root_. That is both confusing
> (where I have relative or absolute import? it's not immediately obvious)
>

Can you define "absolute" and "relative"? In both cases, the first word
after `import ` is simply an identifier that's in scope.

I think what you really want is a way to tell whether that identifier
refers to something in the default package, or something that is in the
current scope due to being imported, or in the current scope for another
reason (like being in the current package or class or method). And that is
a much harder problem.

and ugly (the _root_ prefix is ugly).
>

And is ambiguous as well -- there's nothing stopping you from having a
symbol named _root_ (or having the compiler think so).

It's been suggested before to change the syntax to a leading dot (`import
.outer.inner.Member`), but so far I don't think the power(s) that be
haven't shown any interest. The following may help:

1. Create a SIP that fully documents the proposal
2. Contribute an implementation to the typelevel fork or your own
github-fork of scala.
3. Get positive feedback



> My proposal is to change import statements semantics to make things
> obvious:
>
> Current state:
> import _root_.outer.inner.Member - for absolute imports (usually used when
> there are name clashes)
> import outer.inner.Member - for absolute imports (usually used when there
> are no name clashes)
> import inner.Member - for relative imports
> import parameter.member - for importing from parameters
>
> Proposal for next Scala version:
> import _root_.outer.inner.Member - deprecate _root_ prefix
> import outer.inner.Member - leave as it is
> import inner.Member - deprecate this form of relative imports
> import _.inner.Member - introduce this syntax for relative imports
> import parameter.member - leave as it is
>
> And a version after that:
> import _root_.outer.inner.Member - drop support for _root_prefix
> import outer.inner.Member - keep it
> import inner.Member - drop support for this form of relative imports
> import _.inner.Member - keep it
> import parameter.member - keep it
>
> What do you think about it?
>
> Regards,
> Piotr Tarsa
>
> --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.