Few things

Bill Baxter dnewsgroup at billbaxter.com
Wed Aug 1 13:37:28 PDT 2007


Kirk McDonald wrote:
>>
>> 3) I think it may be better to import "statically" by default (as in
>> python, in that language people suggest to avoid the "from amodule
>> import *" that means import all names from amodule).
>>
> 
> Personally, I almost always try to use selective imports in D:
> 
> import std.stdio : writefln;
> 
> But maybe that's my Python background. :-)
> 
> There was a massive thread on this newsgroup just before static, 
> selective, and renaming imports were added. These were indeed inspired 
> by Python's import semantics, but making everything a static import by 
> default would have broken too much code, and was not deemed worth it. 
> (However, imports were changed from public to private by default at that 
> time.)
> 
> A curious feature of D's imports is that with a regular "import foo;" 
> you can still access the contents of foo by their fully-qualified name. 
> This differs from Python's "from foo import *" in that, though all these 
> imported names have been introduced into the namespace, you can still 
> get at them if they have been shadowed by another name. Combined with 
> the fact that someone importing your module will not get those imported 
> names (since imports are private), the situation is just fine.

The situation is "just fine" from the code & compilers's perspective, 
that is.  From the coder's perspective, however, the default mechanism 
has the same drawback as C++ #includes.  The user has to be intimately 
familiar with the contents of every module included to analyze code 
someone else has written.  Or you need to have a slick IDE that parses 
everything and figures out for you where various symbols are coming from.

--bb



More information about the Digitalmars-d mailing list