Working with modules

Jonathan M Davis jmdavisProg at gmx.com
Fri Feb 15 02:40:34 PST 2013


On Friday, February 15, 2013 11:31:40 Colin Grogan wrote:
> So, I have my structure like so:
> 
> $PROJHOME
> 
>      |-src
>      |
>         |-utils
>         |
>            |- Logger.d // contains "module utils.Logger"
>            |- Props.d //  contains "module utils.Props"
>            |- utils.d //  contains "module utils;
> 
>                                     public import utils.Logger,
> utils.Props;"
> 
> Then, i just 'import utils' in my code.
> 
> Or would I have to have Logger.d in a directory called
> src/utils/Logger/Logger.d to be able to declare the module
> 'utils.Logger'?

utils/logger.d would be utils.logger. utils/logger/logger.d would be 
utils.logger.logger. The file paths and the import paths are identical. It's 
just that the file paths have slashes, and the import paths have dots. And 
unlike Java, there is zero connection between classes and modules. You could 
have many classes in a single module or none at all. Also, it's common 
practice to use all lowercase for module and package names (primarily to avoid 
any risk of different OSes treating the casing differently I believe - i.e. 
Windows doesn't care about casing whereas *nix does; so, on Windows, you could 
screw up you're casing, and it would work, whereas on Linux, it wouldn't).

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list