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

bearophile bearophileHUGS at lycos.com
Fri Nov 13 04:03:42 PST 2009


Leandro Lucarella:

> I'm sorry to bring up another "How about Go's ..." topic, but I think this
> feature is very in sync with D and it should be really easy to implement.
> 
> Go issues an error if you have an import that's never used, to avoid
> unnecessary dependencies.

I think I'd like d compilers to have a switch (-wunused ?) that when present warns me for unused variables, functions, imports, classes, etc. This helps keep the code tidy and tight. Then later IDEs can use this output to underline what's unused.

I use -Wall in C and I find it useful when it tells me that there are unused variables. Unused variables can be stuff that I need to use but I have forgotten to use, or stuff that I have used in an older version of the code and now are not used anymore, etc. Sometimes variables are not used because conditional compilation has disabled a part of the code that uses that variable. In this case I may want to move the variable definition inside the optionally compiled part of the code, this improves the code a little. In many situations I want to know if I have not used them.

Bye,
bearophile



More information about the Digitalmars-d mailing list