Why modules is so strongly limited?

Lodovico Giaretta via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 13 14:04:56 PDT 2016


On Wednesday, 13 July 2016 at 20:58:02 UTC, imbaFireFenix wrote:
> Hello my friends!
> I'm new user of D language and leaarning how it works.
> I'm know C++ and trying Rust, GO and some else and now - D is 
> the best language for me
>
> But I'm confused... Many coders was great work and interesting 
> features, but modules is so strongly limited!!!
>
> https://dlang.org/spec/module.html
> Only one module per file.
>
> but Rust and beta VC++ can multiple file to one module! Why 
> implemented this limit?
> Why modules not written as mix of C# namespace and C++ 
> translation unity? It will be greatly!
>
> But for now for huge project need to do:
>
> ~~~ ~~~ ~~~
>
> module M1;
>
> class M1
> {
> }
>
> ~~~ ~~~ ~~~
>
> module M2;
>
> import M1;
>
> public alias M1 = M1.M1;
>
> ~~~ ~~~ ~~~
>
> import M2;
>
> int main()
> {
>     M2.M1 Something;
> }
>
> ~~~ ~~~ ~~~
>
> Thanks.

Hi!

In this cases, the usual way is to make a package, this way:

== in file MP/M1.d ==
module MP.M1;

// some pieces of the work

== in file MP/M2.d ==
module MP.M2;

// other pieces of the work

== in file MP/package.d ==
module MP;
public import MP.M1;
public import MP.M2;

// public import everything

== in file main.d ==
module main;
import MP;

// can access everything, because publicly imported by 
MP/package.d


More information about the Digitalmars-d mailing list