How about Go's... error on unused imports?

Leandro Lucarella llucax at gmail.com
Fri Nov 13 15:19:03 PST 2009


Nick Sabalausky, el 13 de noviembre a las 17:06 me escribiste:
> "bearophile" <bearophileHUGS at lycos.com> wrote in message 
> news:hdkavm$1b0k$1 at digitalmars.com...
> > Clay Smith:
> >
> >>I would like my all.d files to not give errors :o<
> >
> > "all.d" files are a hack used to patch one of the minor holes of the 
> > current D module system. The right way to do that is with a syntax like 
> > (that must not import the 'foo' name too in the current namespace, only 
> > the names inside "std.foo"):
> >
> > import std.foo: *;
> >
> > Every part of a language needs to be designed with care. Approximate 
> > designs with several holes aren't enough.
> >
> 
> I used to think so, but I'm not so sure anymore. In my Goldie project, one 
> of the modules ("goldie.file") is something with a whole lot of types and 
> details about loading a .cgt file. In the vast majority of use-cases, the 
> Goldie library user has no reason to use any of those directly, so as useful 
> as "goldie.all" is, it would be pointless for me to include that 
> "goldie.file" in "goldie.all", which is exactly what "goldie.*" would do 
> automatically if it existed. Now, certainly, I could just mark everything in 
> "goldie.file" as private, but I do want people to be able to import and use 
> it directly if they want to (Ex, if they want to use Goldie as a springboard 
> for their own .cgt-file handling routines).
> 
> Plus, I'll often have renamed and deliberately unused source files in the 
> same directory as "real" modules, and I wouldn't want them automatically 
> grabbed by ".*". I suppose I could change their extension, but then the 
> editor would get confused, and I'd have to work around that, etc... 

In Python you have the special variable __all__ to mark what do you want
to export when using *. Something similar can be used for this. But
I think import * is a hack, and if somebody use it, he/she should accept
the consecuences (polluting the file with all goldie.file symbols).
I don't think it worth encouraging the use of import * by adding features
to it. I think it should exist, the same I think goto should exist, but
the programmer should be aware of its implications.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Long you live and high you fly
And smiles you'll give and tears you'll cry
And all you touch and all you see
Is all your life will ever be.



More information about the Digitalmars-d mailing list