Simple import question

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 15 16:35:08 PDT 2014


On Wednesday, October 15, 2014 12:11:22 Steven Schveighoffer via Digitalmars-d-
learn wrote:
> On 10/15/14 4:59 AM, Rei Roldan wrote:
> > I don't see how passing all required files to the compiler could
> > possible raise an issue with module discoverability. Unless I'm missing
> > something? In regards to pains if "folder|file names / package|module
> > names" don't match, imho, physical organization of files should never
> > (ever) be of any concern to the compiler.
>
> import a.b.c;
>
> If you didn't pass the file for a.b.c to the compiler, how does it know
> where to find it?
>
> The module system is inherently linked to the filesystem. The way around
> it is to pass all modules to the compiler that you will be importing so
> it knows where they are. But this can lead to problems if you don't
> actually want to compile them, just reference them.
>
> The simplest thing to do is to make your file organization match your
> package/module structure. The compiler understands that and works well
> with it, no matter what you are doing.

In general, if your folder/file layout and package/module layout don't match,
you're asking for trouble. The compiler can be told to look in other places
for modules to import (e.g. dmd.conf does that to tell the compiler where
druntime and Phobos are), but it's generally a bad idea to do that with your
projects. Leave that to libraries that you're compiling against. And you have
to tell it the location of every file that your compiling anyway (unless
you're using rdmd instead of dmd, but that just makes the folder/file layout
that much more important, because then rdmd has to find the modules itself).
It's just all around better to give into the fact that packages are supposed
to correspond to folders and modules are supposed to correspond to files
within those folders - with the exact same layout in both the filesystem and
the package system.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list