Importing again
Chris Miller
chris at dprogramming.com
Wed Jul 12 08:09:30 PDT 2006
Here's my thoughts on import that should satisfy most of what's being
discussed:
1) Some people say "make things inconsistent and have import private by
default" or similar. I say, look at it from a different angle: change what
import really does! Instead of import pulling in all the symbols, allowing
other code to access those symbols through the importing scope, just make
it so it only makes available the symbols to the importing scope, and not
allowing other code to access those symbols through the importing scope.
In effect, it would be like the current private import but would not even
expose these private symbols outside the module. Most modules would use
this style; current use of "private import" would become "import".
2) To achieve what the current "public import" does, "mixin import" could
be used. all.d files would use this style.
3) To achieve what proposed "import foo as bar" does, just import inside a
struct; this can even be done right now!
struct io { import std.stdio; } io.writefln("hi");
Note: if (1) and (2) are implemented, "mixin import" would probably be
needed in the struct.
4) To selectively import single things from modules, I'd just vote for
using the fully-qualified name in an import:
import std.stdio.writefln; // Only import writefln from std.stdio.
More information about the Digitalmars-d
mailing list