Module visibility feature?

Jeremy DeHaan dehaan.jeremiah at gmail.com
Wed Jul 17 04:33:37 PDT 2013


So I was reading this: 
http://wiki.dlang.org/Access_specifiers_and_visibility



After I went through it, I had an idea for a feature that I hope 
would be both intuitive and not too difficult to implement.

We already have the protection attributes public, private, 
protected, and package. Why not have the ability to apply 
something similar to specific modules?

I thought of two different variations to this concept, but I will 
only post about the one that I feel is less convoluted.

I figured that a single keyword should be able to do the trick, 
and package made the most sense. Here's how I'm theorizing this 
could work. If a module is  declared as a "package module" then 
only other modules in the same package are able to import it, 
essentially the way package works currently. Any attempt to 
import that module outside the package would result in an error.


--foo/barstuff.d
package module foo.barstuff;

//stuff the user never needs to see



--foo/bar.d
module foo.bar;
import foo.barstuff;

void someFunction()
{
      //stuff from foo.barstuff
}



--main.d
module main;
import foo.bar;          //ok!
//import foo.barstuff;   //error!

void main(string[] args)
{
      someFunction();
}



Has anything like this been suggested/thought of before? I looked 
through the DIP's but didn't see anything.




More information about the Digitalmars-d mailing list