Thread overview
[Issue 9664] New: Make directory in import path like "a.b.c" a properly supported feature
Mar 08, 2013
jfanatiker@gmx.at
Mar 08, 2013
jfanatiker@gmx.at
Mar 08, 2013
jfanatiker@gmx.at
Mar 08, 2013
Jonathan M Davis
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9664

           Summary: Make directory in import path like "a.b.c" a properly
                    supported feature
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: jfanatiker@gmx.at


--- Comment #0 from jfanatiker@gmx.at 2013-03-08 02:48:35 PST ---
I just made the discovery that putting a D source file named "d" in a
directory named "a.b.c" with a module declaration like:
 module a.b.c.d;

works as expected (can be imported via import a.b.c.d;). This is
actually pretty cool and useful, because there are times where you end up
having a directory containing a single directory containing a single directory,
..., just because of the module path. Having to traverse three folders just to
get to the source code could easily be avoided if this was actually an official
feature.

At the moment this only works if you provide the imported module at the command line, but not if you only provide -I and just compile with -c:


 dmd -c main.d
 main.d(1): Error: module t is in file 'a/b/c/d.d' which cannot be read
 import path[0] = /usr/include/dmd/phobos
 import path[1] = /usr/include/dmd/druntime/import

while this is fine:
 dmd main.d a.b.c/d.d

I think it might be a good idea having the compiler fallback to a folder a.b.c if it exists (or a.b). It could simply prefer a/b/c over a.b/c over a.b.c. In practice only one of them should exist anyway, so the compiler could also just issue an error if ambiguous.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9664


jfanatiker@gmx.at changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9664


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2013-03-08 04:31:15 PST ---
What are the long-term risks of introducing this? Is this a clean feature, or an unclean hack that will cause troubles later?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9664



--- Comment #2 from jfanatiker@gmx.at 2013-03-08 09:04:24 PST ---
(In reply to comment #1)
> What are the long-term risks of introducing this? Is this a clean feature, or an unclean hack that will cause troubles later?

That is the question. I don't see any problems, but if someone does please post them here.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9664


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2013-03-08 09:09:03 PST ---
Modules correlate to files and packages correlate to folders, and the relationship is 1-to-1. That's the design. It's straightforward and simple. This very much goes against that.

And it would be even better IMHO if it weren't legal to have modules which didn't have a module declaration (since you pretty much always have to have it anyway, as it's required if the module is in a package), and I think that allowing for modules to have different names than their file names was a mistake, as it adds extra complication and confusion for no benefit IMHO. But I rather doubt that either of those will change at this point.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9664



--- Comment #4 from bearophile_hugs@eml.cc 2013-03-08 10:31:08 PST ---
(In reply to comment #3)
> Modules correlate to files and packages correlate to folders, and the relationship is 1-to-1. That's the design. It's straightforward and simple. This very much goes against that.

I agree.

Generally I am for keeping the language tidy. Because most times you don't do this, later something comes back to bite your butt.

----------------------

The following things are mostly off topic for this Bugzilla entry:

> And it would be even better IMHO if it weren't legal to have modules which didn't have a module declaration (since you pretty much always have to have it anyway, as it's required if the module is in a package),

If your program is composed by only 1 module (like when you write very short programs), then in my opinion it's not necessary to give it a module declaration.

The module declaration is "infrastructure". Infrastructure is very useful when programs grow bigger, but being forced to put infrastructure when you don't need it, that is in very small programs, is a waste of energy.


> and I think that allowing for modules to have different names than their file names was a mistake, as it adds extra complication and confusion

I agree.


> for no benefit IMHO.

Walter has said there is some benefit (but I don't remember what). Even if this is true, then I think such cases are special. And it's generally bad to break a tidy convention for some special cases. If those cases are so important then they should have a special "syntax", leaving the much more general case clean of 1:1 between module name and file name.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------