Scope modules DIP rough messy draft.

luckoverthere luckoverthere at gmail.cm
Sun Oct 28 12:50:30 UTC 2018


On Saturday, 27 October 2018 at 22:03:12 UTC, 12345swordy wrote:
>> Separating code into multiple files with modules is also good 
>> programming practice :).
> Which sometimes you got break the rules in order to get 
> something done. Like using goto for instance.

You could say the same thing about your one time scripts. You can 
break your rule of encapsulation being a good programming 
practice in order to get your one time script done (into one 
file). Like these rules don't need to be followed to the letter, 
nor should they be. Encapsulation provides benefits for projects 
of larger scale, where it is unrealistically possible for someone 
to know how everything operates, or spending the time to figure 
out how it works. This benefit does not really extend to one time 
scripts. If your scripts are getting so large that it does 
benefit, then they probably shouldn't be one file any longer.

You can try and argue in the DIP that having a single extra-large 
file is good practice and is something D should support, but 
that's honestly an argument you are probably going to fail to 
convince anyone of.

Now you have to consider the complicated situation you are now 
able to achieve with your new system.

How do you handle multiple modules with the same name. You 
mention that this is the same:

module A;

public import B;

is the same as:

module A;

module B
{
     void foo();
}

So that means B is not part of A, correct? So if I do:

import A;

B.foo(); // I can access B without going through A
foo();   // same here

What happens now when you have a separate module with B ?


import A;
import B;


Does the module B in A work with just the separate module B?

Or even worse:

module C;

module B
{
     void foo();
}

///////////////////////////

import A;
import B;
import C;

B.foo(); // Which does this call now ?


These are details you are going to have to iron our, and 
depending on how you want to implement it, will cause the 
implementation for the compiler to become extremely complicated 
(as which is the case with C++ namespaces).





More information about the Digitalmars-d mailing list