Wish: Variable Not Used Warning
Nick Sabalausky
a at a.a
Sun Jul 6 01:49:19 PDT 2008
"Koroskin Denis" <2korden at gmail.com> wrote in message
news:op.udu17gmcenyajd at korden...
> On Sun, 06 Jul 2008 10:45:03 +0400, Walter Bright
> <newshound1 at digitalmars.com> wrote:
>
>> Nick Sabalausky wrote:
>>> I don't suppose there's any chance of DMD getting a warning for
>>> variables/arguments that are declared but never accessed? Just today
>>> alone there's been two bugs I spent 10-30 minutes going nuts trying to
>>> track down that turned out to be variables I had intended to use but
>>> forgot to.
>>
>> The problem with unused variable warnings is they are annoying when
>> you're developing code in an iterative manner. They get in the way when
>> you're commenting out sections of code to try and isolate a problem.
>> They can be a problem when using "version" and "static if" statements.
>>
>> So, why not just turn off the warnings?
>>
>> The problem with warnings is that if there are n warnings, there are
>> essentially n factorial different versions of the language. If you're
>> faced with compiling someone else's code (like you downloaded it off the
>> internet and have to compile it because it only is distributed as
>> source) and warnings go off, is that a bug in the code or not? What do
>> you do?
>>
>> Some shops have a "thou shall compile with warnings enabled, and there
>> shall be no warning messages." That causes problems when you port the
>> code to a different compiler with a different, even contradictory,
>> notion of what is a warning. So then you wind up putting wacky things in
>> the code just to get the compiler to shut up about the warnings.
>>
>> Those kind of things tend to interfere with the beauty of the code, and
>> since they are not necessary to the program's logic, they tend to
>> confuse and misdirect the maintenance programmer (why is this variable
>> pointlessly referenced here? Why is this unreachable return statement
>> here? Is this a bug?)
>>
>> There is a place for warnings, however. That is in a separate static
>> analysis tool (i.e. lint, coverity, etc.) which can be armed with all
>> kinds of heuristics with which to flag questionable constructs. I don't
>> think they should be part of the compiler, however.
>
> Since DMD already has -w switch, why not make use of it? I think it would
> be a good practice to compile your code with -w on just once in a while,
> say, before a public release. This should enable more strick code
> checking, like unused methods, variables, unreachable code etc.
Not to beat a dead horse, but I always have warnings permanently turned on
in every compiler I use, including DMD.
More information about the Digitalmars-d
mailing list