modules
Lars Ivar Igesund
larsivar at igesund.net
Sun Apr 30 02:18:06 PDT 2006
Gabe wrote:
> I don't quite understand the module declaration at the top of source
> files. From the D website, I see that 'Modules have a one-to-one
> correspondence with source files. The module name is the file name with
> the path and extension
> stripped off.' So, I guess my question is: why bother? If the name of the
> file and the name of the module are the same thing, why are you (in
> essence) stating it twice? (It strikes me as a tad 'header.h'y) Wouldn't
> it make more sense to have implicit module declarations, as in Java, where
> 'module std' would represent one directory named 'std' and the name of the
> file simply IS the name
> of the module? Naming the file and then naming the module the same thing
> inside
> the file seems a tad, well, redundant. Also, isn't this why there's the
> somewhat (from my perspective) hacky 'all.d' declarations in some external
> packages? Wouldn't 'module std' and 'import std.*' be more effective
> solutions, simply relying on the compiler and PATH variables to sort out
> the rest?
>
> But then again, I could totally be missing something here.
> -Gabe
If you for foo.d only sets
module foo;
then it would be redundant, but by using a form like
module bar.baz.foo;
you have stated that the file foo is part of the bar package and baz
subpackage and the import root for all files in that package are placed in
the directory where you find bar.
Also, the module names functions as your namespace. If you have equally
named functions in two modules, and you need to use them both from one
file, you would have to call them as bar.baz.foo.func(); and
bar.baz.boodle.func();
--
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi
More information about the Digitalmars-d-learn
mailing list