Wish: Variable Not Used Warning

Nick Sabalausky a at a.a
Thu Jul 10 12:20:54 PDT 2008


"Markus Koskimies" <markus at reaaliaika.net> wrote in message 
news:g54b6m$1h9i$4 at digitalmars.com...
> 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 :)
>

I'd prefer a warning, but I'd be fine with all this.

> 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 :)

I, too, like to tackle all that stuff right when I compile. But whenever 
I've refered to warnings as "optional errors" here, what I meant was that 
it's impossible to turn off "treat warnings as errors".  Even if warnings 
are not treated as errors, they're still going to show up on your screen 
(provided you at least enabled them, of course), so you can still choose to 
deal with them right then and there.

The benefit is that you wouldn't have to fix (or wait for a fix for) any 
warnings in any third-party source libraries you use. Also, while I can't 
confirm or deny this at the moment, someone here said that -w compiles 
currently halt at the first warning. If that's the case, then disabling 
"treat warnings as errors" would let you see all the warnings at once, not 
just the first one. Plus, allowing "treat warnings as errors" to be disabled 
would decrease the strength of the phenomenon Walter and others described 
where warnings effectively create multiple versions of the same language. 
The pheonomenon would only occur in places that take "No warnings allowed!" 
to an obsessive/compulsive/irrational level (rather than a merely sensible 
level), instead of happening to everybody.





More information about the Digitalmars-d mailing list