Working with modules

Jeremy DeHaan dehaan.jeremiah at gmail.com
Fri Feb 15 19:50:10 PST 2013


On Friday, 15 February 2013 at 10:01:35 UTC, Jonathan M Davis 
wrote:
> On Friday, February 15, 2013 10:51:00 Colin Grogan wrote:
>> Does anyone here have any alternatives for me so that in my
>> 'engine' or 'main' classes I can simply write:
>> 
>>      import utils;
>> 
>> and still have my source files neatly laid out in manageable
>> chunks?
>
> The only way that you can have a single import which imports 
> multiple modules
> is if the module that you're importing publicly imports the 
> other modules. And
> there is no way to do something like
>
> import utils.*;
>
> And remember that modules always correspond to files, and 
> packages correspond
> to folders, so there's a one-to-one correspondance between what 
> you'd import
> and what you'd put in the file system (unless you use public 
> imports to make it
> so that importing a module imports stuff from outside that 
> module).
>
> - Jonathan M Davis



I was actually going to post a similar question, but it looks 
like this would be a better place to post!

I know that a module can only be defined once, but I feel like 
there could be times where it would be helpful to be able to have 
the same module defined in separate files and I have an example. 
Right now, I am working on a binding and I am making use of the 
package access modifier to allow me to use internal objects that 
the end user will not be able to access directly. Problem is, my 
source files have many classes and are pretty convoluted. If I 
could define the module more than once I could split the source 
files up and it would be easier to work on, but I would still be 
able to share package declared objects and methods between 
modules like I do now. If I put the source files into their own 
packages, they are now hidden from source files I want them to be 
used in.

Here's what I mean:


mainpackage.system
mainpackage.window
mainpackage.graphics

Anything defined with package is accessible between these.

But...
mainpackage.system.thing1
mainpackage.system.thing2
mainpackage.window.thing3
etc...

Now things defined as package in mainpackage.system.thing1 are 
only accessible in mainpackage.system, but can't be accessed in 
mainpackage.window.

Thoughts?


More information about the Digitalmars-d-learn mailing list