Wish: Variable Not Used Warning

Unknown W. Brackets unknown at simplemachines.org
Sat Jul 5 18:41:21 PDT 2008


Well, I think the problems center around the following:

1. In many cases a "warning" in some C/C++ compilers really should be an 
error.  The line seems to be difficult and arguable.

2. Compilers don't agree on warnings.  This is sorta #1 but for those 
who ignore warnings, it means their code might (surprisingly to them) be 
non-portable.

3. Warnings beg warning suppressions methodologies, because they are 
sometimes made incorrectly (otherwise they'd be an error, no?)

4. It creates more of a rift between people who are pedantic about 
warnings, etc. and people who are not.  In my experience at least, 
maintenance programmers, newer programmers, and experienced programmers 
can all fit into those two groups in awkward ways.

A lot of these points are well expressed by PHP's (imho very flawed) 
error reporting.  Most PHP programmers learn to turn warnings off before 
they even learn what a for loop is.  I've taken many large open-source 
or proprietary PHP codebases, simply turned on warnings, and been able 
to point out a handful of very obvious bugs in short order.

I think breaking it like D does is an excellent strategy based on real 
world, practical problems with warnings.

In any case, I would very much like to see (or develop) a code-standards 
enforcing lint tool for D.  This wouldn't be that hard to make based on 
dmd's open source frontend, and could be configured to enforce such 
guidelines as:

1. No commented out code (WebKit uses this guideline, I do with some 
languages as well.)

2. Either consistent or specific indentation style.

3. Variable usage and naming.

4. Use of unstable, deprecated, or untrusted language or library features.

But I really think that works better as a separate tool (that could be a 
checkin hook for whatever preferred versioning system, etc.)  This helps 
especially since some people don't compile things (although they should) 
before checkin, and actually recompiling automatically is often wrong.

-[Unknown]


bearophile wrote:
> Koroskin Denis:
>> Agreed, put it into a bugzilla, otherwise it may get lost.
> 
> I have written this too in one of my lists of suggestions I have posted in this newsgroup, probably more than one year ago :-)
> 
> 
>> Since D has no warnings, it should be an error, but it would break too  
>> much of the existing code.
> 
> What's bad about warnings?
> 
> Bye,
> bearophile



More information about the Digitalmars-d mailing list