[Issue 3503] [module] Imports should be static by default
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 14 10:32:19 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3503
--- Comment #8 from Leandro Lucarella <llucax at gmail.com> 2009-11-14 10:32:18 PST ---
(In reply to comment #7)
> IMHO the purpose of a module system is to stay the heck out of the user's way
> and let the user get on w/ solving the real problem. It should only make noise
> when there's a real ambiguity. Making imports unnecessarily verbose,
> complicated, or fine-grained is just a bad idea. D already deals well with
> collisions. When there's not a collision, I personally prefer to have stuff
> "just work" without having to care that there are namespaces.
What you say is good for *writing* code, but it's *really* bad for *reading*
code and tracking dependencies. It's subject to highjacking too (in very, very
weird and special cases, I'm aware of that ;).
Anyways, in conjunction with bug 3504 and 3505 I'm suggesting just a change on
the default, you can get the same behavior with import *.
They idea is to make the default safer and less typing. Now if you want the
"unsafe" (pollute everything) behavior you type:
import std.stdio;
import std.algorithm;
import std.conv;
writeln();
sort();
to();
And if you want a safe way (but very verbose) to import things, you have to do:
static { // not so much extra typing
import std.stdio;
import std.algorithm;
import std.conv;
}
// lot of extra typing (repeating std.)
std.stdio.writeln();
std.algorithm.sort();
std.conv.to();
If you want a reasonable, not-so-much-typing safe way to import things, you
have to do:
// some extra typing (and repeated code)
import stdio = std.stdio;
import algorithm = std.algorithm;
import conv = std.conv;
}
// no repetition, not so much typing
stdio.writeln();
algorithm.sort();
conv.to();
If all the features I'm proposing are implemented, the reasonable,
not-so-much-typing safe way to import things is the default:
import std.stdio;
import std.algorithm;
import std.conv;
stdio.writeln();
algorithm.sort();
conv.to();
And you can get the promiscous old behavior with a little more typing (3 chars
per import):
import std.stdio: *;
import std.algorithm: *;
import std.conv: *;
writeln();
sort();
to();
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list