Thread overview
Module self-imports
Oct 05, 2012
Andrej Mitrovic
Oct 05, 2012
Dmitry Olshansky
Oct 05, 2012
David Nadlinger
Oct 05, 2012
Andrej Mitrovic
October 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8447

There's a bunch of self-imports (only a few) in Phobos, they're usually in unittest blocks. I'm thinking this was put there for convenience (so you can copy the snippet into a different module and get an import statement for free).

Question: Should self-imports be banned? And if so, should they be completely banned or only banned in module scope (allow them in function/unittest blocks)?

I have a gut feeling that many people inadvertently (or on purpose) have self-imports in their projects, and if this was banned there might be a lot of projects that stopped compiling.

*Note*: I'm talking about direct self-imports, meaning A->A, not A->B->A:

module foo.bar;
import foo.bar;  // would be an error
October 05, 2012
On 05-Oct-12 07:43, Andrej Mitrovic wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=8447
>
> There's a bunch of self-imports (only a few) in Phobos, they're
> usually in unittest blocks. I'm thinking this was put there for
> convenience (so you can copy the snippet into a different module and
> get an import statement for free).

Haven't thought of that.

> Question: Should self-imports be banned? And if so, should they be
> completely banned or only banned in module scope (allow them in
> function/unittest blocks)?
>

I suspect that we can't break code. So the only thing I'd want now is for these statements to *truly* have no effect.
It seemed to have some ;)

> I have a gut feeling that many people inadvertently (or on purpose)
> have self-imports in their projects, and if this was banned there
> might be a lot of projects that stopped compiling.
>
> *Note*: I'm talking about direct self-imports, meaning A->A, not A->B->A:
>
> module foo.bar;
> import foo.bar;  // would be an error
>


-- 
Dmitry Olshansky
October 05, 2012
On 10/4/12 11:43 PM, Andrej Mitrovic wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=8447
>
> There's a bunch of self-imports (only a few) in Phobos, they're
> usually in unittest blocks. I'm thinking this was put there for
> convenience (so you can copy the snippet into a different module and
> get an import statement for free).
>
> Question: Should self-imports be banned? And if so, should they be
> completely banned or only banned in module scope (allow them in
> function/unittest blocks)?
>
> I have a gut feeling that many people inadvertently (or on purpose)
> have self-imports in their projects, and if this was banned there
> might be a lot of projects that stopped compiling.
>
> *Note*: I'm talking about direct self-imports, meaning A->A, not A->B->A:
>
> module foo.bar;
> import foo.bar;  // would be an error

Interesting. I don't see what bugs or inefficiencies that might cause, so I'd say by the TAWD (Turtles All the Way Down) principle we should allow them as a no-op.

Andrei
October 05, 2012
On Friday, 5 October 2012 at 11:46:04 UTC, Andrei Alexandrescu wrote:
> Interesting. I don't see what bugs or inefficiencies that might cause, so I'd say by the TAWD (Turtles All the Way Down) principle we should allow them as a no-op.

I'd strongly second that. With disallowing self-imports, using imports in both string and template mixins might become a major pain.

I can't see a good reason why self-imports should be more problematic than normal forward references within a module, since they can just be ignored.

David
October 05, 2012
On 10/5/12, David Nadlinger <see@klickverbot.at> wrote:
> I can't see a good reason why self-imports should be more problematic than normal forward references within a module, since they can just be ignored.

I don't see either, but Dmitry mentioned he had forward reference issues. Maybe *that* should be fixed instead, but we need a test-case first. :)