How about Go's... error on unused imports? -> marking unused imports

Leandro Lucarella llucax at gmail.com
Fri Nov 13 08:42:17 PST 2009


Ellery Newcomer, el 13 de noviembre a las 08:36 me escribiste:
> >> Secondly, what if I version out some code, wouldn't want to version the
> >> import too.
> > 
> > Why?
> > 
> 
> Given the way DMD currently works, such a feature could only say this
> import is unused in this version configuration. There's no way to know
> if the import is used in a different version configuration, short of
> running compiles for every possible one.

I know, my question was "why don't you want to put the import inside
a version statement"?

BTW, I just saw that you can use an import for which you don't use any
symbols (for example, if you want the module initiazation to be executed),
you just have to alias the import to the "blank" identifier (_):

import _ "something";

I guess something like this can solve this issue too (if unused imports
are errors/warnings). It's a valid use case too since D have module
initialization too. And this got me thinking, that importing something you
don't use might execute code you don't want to be executed (I think
because of this, unused imports are not just an "environmental" problem).
So I think that this can be a good feature for D too.

Since D doesn't have a "blank" identifier, maybe void can be used as
a special case (it's used for other special cases, like no initialization
already, so):

import void = something;

It looks a little confusing though. But maybe someone can figure out an
alternative syntax.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
El techo de mi cuarto lleno de cometas



More information about the Digitalmars-d mailing list