In the D programming language, what is the difference between
private import tango.io.File;
and
import tango.io.File;
?
In the D programming language, what is the difference between
private import tango.io.File;
and
import tango.io.File;
?
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.
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
:
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!
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.