Make imports private by default

Norbert Nemec Norbert at Nemec-online.de
Thu Apr 13 04:56:33 PDT 2006


I fully agree. The rule "everything in a module is public by default" is
just too simple. A "default" should always consider what is the best
solution if people are too lazy to think about the issue.

Just consider the two options:

* "imports public by default": many libraries will export tons of
garbage, just because the authors were lazy. The clear structure of a
library will be washed out because, to the user, every symbol is everywhere.

* "import private by default": a module will usually export only a small
and distinct set of symbols, so you can easily pick those modules that
you actually need with minimal risk of conflicts. As an alternative, a
large library can always offer "collective modules" that just consist of
a list of public imports.

So, instead of just sticking to simple principles, the decision should
be made based on the effect on the language as a whole.



Derek Parnell wrote:
> On Thu, 13 Apr 2006 20:42:14 +1000, Frank Benoit <benoit__ at __tionex.de> 
> wrote:
> 
>> There was a posting of Tyro
>> http://www.digitalmars.com/d/archives/digitalmars/D/11081.html
>>
>> Most ppl seconded that.
>>
>> The problem is, that D does not work if you use non-private imports all
>> the time. Suddenly there are conflicts.
>>
>> A public import make the imported module part of this modules interface.
>> This can (and should) be made public explicitely.
>>
> 
> I think the reason is that all other unadorned symbols in a module are 
> public so therefore why make an exception with imports.
> 
> If that is the reason, I think it is not a good one. It assumes that 
> consistency is always a good thing, that new programmers to D are too 
> simple-minded to remember this 'exception', that C/C++ programmers are
> too  simple-minded and thus will get confused, that remembering to type 
> "private { import ... }" is easier to do that remembering (if this is 
> fixed) that imports are already private, that porting C programs is
> going  to be the major activity of D coders in the future, ...
> 
> Yes, I do think this is a foolish, bureaucratic, simplistic decision to 
> make imports public by default.
> 
> Who here is going to be seriously affected if imports are made private
> by  default?
> 



More information about the Digitalmars-d mailing list