Pathological import symbol shadowing

matheus matheus at
Wed Nov 18 18:58:53 UTC 2020

On Wednesday, 18 November 2020 at 18:10:58 UTC, H. S. Teoh wrote:
> Local imports are good in the sense that you minimize namespace 
> pollution: import the symbol only where you need them, not 
> anywhere else.

> They are also good for encapsulation: cut and paste your 
> function into another module, and it Just Works.  Whereas if it 
> depended on symbols imported at the module level, you now have 
> to copy-n-paste that import into the new module.  And we all 
> know what happens to that blob of imports at the top of the 
> file: it just keeps growing and growing, and nobody dares 
> delete it because you don't know what else might depend on it.

Yes that's true, but on the other hand you will need to duplicate 
or repeat yourself with local imports, like:

void bar(){
     import std.stdio;

void foo(){
     import std.stdio;

void main(string[ ] args){

Wouldn't this generate some pollution as well as your program 


More information about the Digitalmars-d mailing list