Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In D, what's the difference between a private import and a normal import?

Tags:

d

In the D programming language, what is the difference between

private import tango.io.File;

and

import tango.io.File;

?

like image 256
lowerkey Avatar asked Aug 19 '10 04:08

lowerkey


2 Answers

There was a time when imports were public by default; that is, when you imported another module, its contents would not only be visible from within your module but also from any module that imported your module.

Eventually, it was changed so that they were private by default.

However, there's a few reasons to manually specify private:

  1. Imports can be made public if they're in a public context. For example:

    public:
    
    // Lots of stuff
    
    import blah; // oh no, everyone can see my imports!
    
  2. DMD teems with import-related bugs. For example, selective imports are public by default in spite of supposedly being private. This can cause all sorts of horrible nightmare scenarios where symbols (erroneously) imported publically in one module cause symbols in a completely different module to simply vanish and break your program.

In other words, they're probably private in Tango because the devs have worked with DMD for too long to trust it to get this stuff right.

like image 199
DK. Avatar answered Sep 22 '22 10:09

DK.


In D 2.0, private import is synonymous with import, as opposed to public import. By default, imports are private. See the Modules documentation

EDIT: By default, imports are private D 1.0, too.

like image 41
stephan Avatar answered Sep 20 '22 10:09

stephan