[Issue 3503] [module] Imports should be static by default
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 14 06:39:52 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3503
Bill Baxter <wbaxter at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |wbaxter at gmail.com
--- Comment #3 from Bill Baxter <wbaxter at gmail.com> 2009-11-14 06:39:51 PST ---
I'm torn on this one. I used to be all for it, but looking over my code,
non-static imports are by far the majority.
But I know in Python static default works out well. And Python folks generally
encourage to always use either static or renamed import.
But I think Python does not have the ability to report about conflicting
symbols in different modules. That's a huge difference. If module "foo" and
module "bar" both have a blarf() function, then I think it's just the last
import who's definition wins. That's a recipe for disaster. So Python users
have to be very very careful about what they stick in the default namespace.
D doesn't have that problem since the compiler will tell you if two symbols
with the same name get imported.
Still, static/renamed imports are certainly good for making code more readable.
If there are 20 imports and I see a call to "format()" somewhere, it's a pain
to try to track down which of those modules defines "format()". But this is
something a good IDE remedy, with a "Go to definition" button.
Another thing to consider is that usually D modules have at least a package,
like foo.bar. And in the case of Tango often several. In most cases that makes
the full module name too long for you to want to type it again and again. So
static import is almost never what you want. You either want full import, or
you want renamed import. So by making this change you make the default the
least useful thing, which just seems the wrong choice for a default.
If the default were something like a renamed import, using the leaf name as the
name, that might be reasonable:
I.e.
import std.stdio;
Would mean the same as this currently:
import stdio = std.stdio;
--
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