Wish: Variable Not Used Warning

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sun Jul 27 06:56:01 PDT 2008


Walter Bright 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?
> 

You have a distorted notion of warnings. Warnings are not errors (and by 
corollary are not "optional errors" also). They are simply messages 
which indicate some "strange" situations in code, which suggest some 
attention from the developer (now or in the future).
That's why other compilers have an *option* such as 
"treat-warnings-as-errors". If they were errors, they wouldn't need that 
option, cause they would already be treated as errors (cause they would 
*be* errors...), lol. :(

You (Walter) and other people, may be inclined to disagree, especially 
if you are heavily biased torwards C++, where warnings, like you said, 
have been used for *things that should have been errors*, and have 
created this whole messed up and confused situations, and scenarios 
where people think C++ code should compile without errors, etc., etc.. 
But that is just a scenario arising from C++ fucked-up-ness.

If you (and others) still don't agree, which you probably won't, then 
let's not argue semantics, and just call this notion of warnings that I 
defined before as "cautions".
_ With this in mind, what's wrong with the compiler generating messages 
(and just messages, not errors) for certain suspicious code situations, 
such as unused variables? Just that, what do you say? _


-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list