Wish: Variable Not Used Warning

Robert Fraser fraserofthenight at gmail.com
Thu Jul 10 12:31:50 PDT 2008


Markus Koskimies Wrote:

> On Wed, 09 Jul 2008 17:53:52 -0400, Nick Sabalausky wrote:
> 
> > In a "properly defined language", how would you solve the problem of
> > unintentionally-unused variables?
> 
> My suggestion: just give error. No need for "unused" keyword, just 
> comment out code that has no effects.
> 
> For function arguments, if they are unused but mandatory because of 
> keeping interface, leave it without name if it is not used.
> 
> Furthermore, give also errors unused private/static things. If they are 
> not used, why are they in the code? Just comment them out.
> 
> In similar manner, warn about conditional expressions that have constant 
> value (like "uint a; if(a > 0) { ... }"), code that has no effect and all 
> those things :)
> 
> And yes, warnings could be considered as "optional errors" for us who 
> think that it's best to tackle all sorts of quirks & potential bugs at 
> compile time and not trying to find them with runtime debugging. As long 
> as the warning makes some sense and can be circumvented in some 
> reasonable way, just throw it to my screen :)

In a final release, unused things are signs of errors. When writing code, unused variables (perhaps they were used in a commented-out section?) are a dime a dozen. If unused vars were errors in any language, it would be for development.

With our linkers, unused imports are potentially more dangerous than an unused local variable that the code generator throws out.



More information about the Digitalmars-d mailing list