A suggestion for modules names / sharing code between projects

Mike Parker via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 2 17:52:47 PST 2016


On Thursday, 3 March 2016 at 01:47:08 UTC, Mike Parker wrote:

> The package and module system is very intuitive to me and has 
> been from the beginning, so I'm still not quite sure what it is 
> about it that bothers you. The two major issues you bring up 
> here, the need to import package.module and how to structure 
> your projects, are easily resolved. Am I misunderstanding 
> something?

I should also say that I get the impression that you aren't 
considering the package name as part of the module name. Maybe 
that's the root of your problem. As I said in a previous post, 
your desire to use the default package for everything so that you 
can simply import foo is perfectly fine. The price of doing that, 
as you point out here, is that you can easily run into conflicts. 
Packages are the solution to avoiding them and package names are 
part of the module name, such that module foo is no longer just 
foo, but mypack.foo. Without a module declaration, the compiler 
would need some other way to know that 
C:\\src\libs\mylib\mypack\foo.d is actually mypack.foo and not 
c.src.lib.mylib.mypack.foo (which again, is why it only uses the 
file name when no module declaration is given). I can't think of 
a better way to do it than putting it right there in the source 
file. Using a command line switch would not be scalable.


More information about the Digitalmars-d mailing list