Wish: Variable Not Used Warning

Yigal Chripun yigal100 at gmail.com
Sun Jul 27 10:04:48 PDT 2008


Bruno Medeiros wrote:
> 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.
> 

Even better would be to have something like clang which offers a
collection of libs (codegen, semantic analysis, parsing, etc..) and an
API for each lib. that way the descent folks could have just used the
semantic analysis and parser DLLs of the compiler and the respective
APIs instead of having to port the DMD frontend from c++ to Java. I
think Ary wrote here once that he had to replace all the gotos with
exceptions or something like that. That doesn't sound good or
maintainable to me..



More information about the Digitalmars-d mailing list