Wish: Variable Not Used Warning

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sun Jul 27 09:35:17 PDT 2008


Koroskin Denis wrote:
> On Sun, 27 Jul 2008 17:56:01 +0400, Bruno Medeiros 
> <brunodomedeiros+spam at com.gmail> wrote:
> 
>> 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? _
>>
>>
> 
> Now I agree with Walter on that matter. Compiler's job is to compile an 
> executable. As a gentoo user when I compile something (and I do it alot 
> :p ) I expect two messages: "build finished" *or* "build failed for the 
> following reason: ...". All those warning are *not for me*, they are for 
> developers and needed during development time only. Imagine you are 
> updating a web-browser or some other application and get all those 
> "comparison between signed and unsigned types" messages. Do you want to 
> read them?
> 

I too was talking about development time only. If you're compiling as a 
user, then yes there should be an option that suppresses various output, 
warnings or not.

> OTOH, I want for my code to be constantly analyzed for suspicious 
> situation but _only during development time_. That's why I use IDE. And 
> my IDE should help me as I type: syntax highlighting, code autocomplete, 
> refactoring *and* warnings. It's almost free for IDE to analyze my code 
> for possible errors. But compiler's job is to compile *or* reject the 
> code, and it should do it as fast as possible without spending time for 
> looking into suspicious situations.
> 
> Compiler and IDE tasks do often overlap, of course, but it doesn't mean 
> that they should be merged into single solution.
> 
> Just my $0.02...

Like you said, the compiler and IDE tasks overlap. In D's case, if DMD 
did a proper warning analysis, then an IDE could use the compiler to 
present warnings to the user in a proper manner (like squiggles in the 
source code editor). In Descent's case, it would be particularly easy to 
do that, since it has an embedded/ported DMD frontend, and already does 
the same for compiler errors.

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