Why the compiler dosen't enforce correct module declarations?
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Sat May 12 12:15:58 PDT 2007
Ary Manzana wrote:
> Manfred Nowak escribió:
>> Ary Manzana wrote
>>
>>> In http://www.digitalmars.com/d/module.html it states:
>>
>> | The ModuleDeclaration sets the name of the module and what package
>> | it belongs to. If absent, the module name is taken to be the same
>> | name (stripped of path and extension) of the source file name.
>>
>> Please read carefully.
>
> So what's the point of settings a package and module name different than
> what's in the filesystem?
Its useful as an alternative means of doing platform-versioning. (At least I remember
this working... I might just be crazy.) For example:
Given project:
main.d - module main;
util_win32.d - module util;
util_linux.d - module util;
You may now simply `import util;` in main, and on the command line pass the appropriate
util module. I'm sure there might be another use as well, but I admit that even this one
has limited value -- aside from avoiding having a redundant version(){}else{} block at the
beginning of all modules importing util, but we have two different ways of avoiding that:
a go-between module with a version'd public import of util, or a mixin. (Possibly even a
mixin(import()).)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list