www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Module self-imports

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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
Oct 04 2012
next sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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
Oct 05 2012
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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
Oct 05 2012
parent reply "David Nadlinger" <see klickverbot.at> writes:
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
Oct 05 2012
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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. :)
Oct 05 2012