How to break module into multiple file.

Jason House jason.james.house at gmail.com
Fri May 13 06:11:57 PDT 2011


I wonder a bit why you want one file per object? Is it to avoid unnecessary imports? Make finding object definitions easier? Or a style preference? I think replies by others covered all but the first question. I use the "import std.foo: bar, baz;" syntax for that.

Generally speaking, separating unrelated code is a good idea, but I think closely coupled code should go in the same file. I've heard that circular imports are buggy in D.

Matthew Ong Wrote:

> Hi,
> 
> According to:
> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=135947
> 
> And also source code within dmd2/src
> It seems that there is only one file per module.
> 
> Is module similar to a single java package and namespace in VC++/C#?
> 
> If yes, most name spaced programming language allow breaking of single module
> into multiple
> file to store various logically linked class and separate them when they are not.
> 
> Like module Collection may have:
> Common interfaces for both HashMap, LinkedList and hashlist.
> 
> But they should be all be in different source file(HashMap.d, LinkedList.d,
> HashList.d) but
> logically within the same module collection.(Directory)
> How do I do that within D? what is the directory layout of the project?
> 
> Matthew Ong



More information about the Digitalmars-d-learn mailing list