Code-File structure

Henrik Valter Vogelius Hansson groogy at groogy.se
Tue Jun 12 12:35:46 PDT 2012


On Tuesday, 12 June 2012 at 18:07:45 UTC, Francois Chabot wrote:
> On Tuesday, 12 June 2012 at 07:04:15 UTC, Henrik Valter 
> Vogelius Hansson wrote:
>> Hi!
>>
>> I'm new to D and trying everything out. Got the basics down 
>> which are very straightforward and similar to other languages. 
>> My professional background is primarily in C/C++-variants and 
>> Ruby if it helps.
>>
>> I have a problem with how modules, packages and files work. I 
>> don't really know how I am supposed to organize my code. I 
>> like namespaces from C++ which is probably my curse. What I 
>> want to write is code similar to this:
>>
>> MyClass obj = new MyClass();
>> SomePackage.SecondClass secondObj = new 
>> SomePackage.SecondClass();
>>
>> Problem here is that SecondClass is a module. Is there some 
>> nifty trick I can do here to solve this? I tried with just 
>> having one module file which would hold all it's classes and 
>> functions but that backfired very quickly as you can imagine 
>> since it grew too large too quickly for most simple things.
>>
>> I am open to any suggestions of course which would make it 
>> simple for me to have a good structure with my files and also 
>> make my code easily readable. Though if possible I would like 
>> anything that goes under the package/module can somehow be 
>> placed in it's own folder.
>
>
> You can get the equivalent of C++ namespaces with the following 
> project structure:
>
> project_folder
>    - SomePackage.d
>    - SomePackage_impl
>        -SecondClass.d
>
>
> and then in SomePackage.d:
>   module SomePackage;
>   public import SomePackage_impl.SecondClass;

Nice thanks! That will help me out a lot!
Is there a "D" way to do it? Or is D too young to have that yet?

You know Ruby has a "Ruby" way to do stuff. Like using blocks to
do some things instead of the traditional way in C style
languages.


More information about the Digitalmars-d-learn mailing list