module vs import

Koroskin Denis 2korden at
Tue Jun 10 03:57:35 PDT 2008

On Tue, 10 Jun 2008 14:17:10 +0400, Tomas Lindquist Olsen  
<tomas at> wrote:

> Tomasz Sowiñski wrote:
>> Robert Fraser Wrote:
>>> The "module" keyword is used to assign a name to your module (which  
>>> incidentally must coincide with its filename & folder structure) while  
>>> "import" gives you access to the module with the given name.
>>  By the way, why do you have to repeat the filename in the file itself?  
>> I'm sure there must be some reason, but I can't see it now.
>>  Tomek
> First, the module identifier *must* not coincide with the file path.
> One case where this is useful, and not mentioned in the other replies (I  
> think), is when a module can have multiple implementations. The module  
> that imports find could be a .di file, for example foobar.di, while the  
> actual implementation .d files could have other file names, for example  
> foobar_win32.d, foobar_linux.d etc, here the module identifier is  
> necessary to mangle symbols correctly.
> If you're using Makefiles or simple scripts to build your software this  
> is an entirely feasible setup!
> Of course D has the 'version' keyword for this, but sometimes the code  
> can be very big and seperate files might be more maintainable. I  
> personally prefer switching my editor to another file than scrolling a  
> hundreds of lines to look at the other implementation.
> Tomas

Good point!

More information about the Digitalmars-d-learn mailing list