Thread overview | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 05, 2005 What happens with unused variables? | ||||
---|---|---|---|---|
| ||||
"dmd -w" on the following code should produce a warning like "unused variable ii" or similar. Usually helps a lot :)
<snip>
int main(){
int ii;
return 0;
}
<snip>
Best,
Tiago
--
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
|
December 05, 2005 Re: What happens with unused variables? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tiago Gasiba | "Tiago Gasiba" <tiago.gasiba@gmail.com> wrote in message news:dn1611$grl$1@digitaldaemon.com... > "dmd -w" on the following code should produce a warning like "unused variable ii" or similar. > Usually helps a lot :) > > <snip> > int main(){ > int ii; > > return 0; > } > <snip> This isn't a bug, it's by design <g>. Warnings about unused variables can get rather annoying when they're intended. |
December 06, 2005 Re: What happens with unused variables? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Mon, 5 Dec 2005 10:00:15 -0800, Walter Bright wrote: > "Tiago Gasiba" <tiago.gasiba@gmail.com> wrote in message news:dn1611$grl$1@digitaldaemon.com... >> "dmd -w" on the following code should produce a warning like "unused > variable ii" or similar. >> Usually helps a lot :) >> >> <snip> >> int main(){ >> int ii; >> >> return 0; >> } >> <snip> > > This isn't a bug, it's by design <g>. Warnings about unused variables can get rather annoying when they're intended. And can get extremely annoying when they're *not* intended. -- Derek (skype: derek.j.parnell) Melbourne, Australia "A learning experience is one of those things that says, 'You know that thing you just did? Don't do that.'" - D.N. Adams 6/12/2005 12:05:08 PM |
December 06, 2005 Re: What happens with unused variables? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell schrieb: > On Mon, 5 Dec 2005 10:00:15 -0800, Walter Bright wrote: > >> "Tiago Gasiba" <tiago.gasiba@gmail.com> wrote in message news:dn1611$grl$1@digitaldaemon.com... >>> "dmd -w" on the following code should produce a warning like "unused >> variable ii" or similar. >>> Usually helps a lot :) >>> >>> <snip> >>> int main(){ >>> int ii; >>> >>> return 0; >>> } >>> <snip> >> >> This isn't a bug, it's by design <g>. Warnings about unused variables can get rather annoying when they're intended. > > And can get extremely annoying when they're *not* intended. > How about a switch in the compiler? Two proposals: 1) Something like -wv (warn on unused variables) ? IMHO the best solution 2) Several warning levels like -w1 - normal warnings -w2 - normal + unused variables -w3 - something else? Not very clean solution though... Best, Tiago -- Tiago Gasiba (M.Sc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler. |
December 07, 2005 About DM's Warnings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote: > "Tiago Gasiba" <tiago.gasiba@gmail.com> wrote in message > news:dn1611$grl$1@digitaldaemon.com... > >>"dmd -w" on the following code should produce a warning like "unused > > variable ii" or similar. > >>Usually helps a lot :) >> >><snip> >>int main(){ >> int ii; >> >> return 0; >>} >><snip> > > > This isn't a bug, it's by design <g>. Warnings about unused variables can > get rather annoying when they're intended. > > Why is it that Digital Mars compiler's option to enable warnings does not only warning-notification but also error-on-warning? And there isn't even a way to do just the first? In *all* compilers I've seen so far, (gcc, javac/JDT, VS C++, VS C#, etc., and maybe some more I don't recall) the warning semantics are all the same: by default "notify" about warnings, and only with an extra option do the warnings cause a compilation error/stop. This is what makes more sense in terms of nomenclature, because if a "warning" if allways an error, then it is not a "warning", it is a... well, "prohibition" or "order" or something... But more importantly, it is also what makes more sense in terms of programming/development, because it is more useful to have no-error warnings, allways enabled. Otherwise, no wonder one finds DM's warnings about unused variable annoying (as well as other warnings), since they halt compilation in unwanted situations. The end result is the coder rarely compiling with -w , is it not? I do agree that some of the traditional warnings (specially in the C/C++ world), such as use-of-uninitialized-variable, could be treated allways as errors, as they probably signify wrong code. However, some other types of warnings, such as unused-variable, unreachable-code, etc., are pretty much innocuous, and they occur frequently and *naturally* during developing/testing, where often there is incomplete code. That's why it is a royal pain to have error-on-warning enabled as such. -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural." |
December 07, 2005 Re: About DM's Warnings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | On Wed, 07 Dec 2005 01:43:36 +0000, Bruno Medeiros wrote: >That's why it is a royal pain to have > error-on-warning enabled as such. I believe that Walter is philosophically opposed to the concept of 'warning'. Basically, if something is worth warning you about, it is worth fixing. So in effect there is nothing different between a warning and an error. I do not support this philosophical opinion. I tend to think that giving more freedom of expression to coders is better than nannying them. In other words, I think we should let coders choose the type of dangers they are willing to be responsible for. Give coders warnings, if that's what they ask for, and keep quiet, if that's what they ask for. And only issue an error if the compiler cannot achieve a valid object code output. A compiler is a tool to assist coders. -- Derek (skype: derek.j.parnell) Melbourne, Australia "A learning experience is one of those things that says, 'You know that thing you just did? Don't do that.'" - D.N. Adams 7/12/2005 1:53:05 PM |
December 07, 2005 Re: About DM's Warnings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> On Wed, 07 Dec 2005 01:43:36 +0000, Bruno Medeiros wrote:
>
>> That's why it is a royal pain to have error-on-warning enabled as such.
>
> I believe that Walter is philosophically opposed to the concept of
> 'warning'. Basically, if something is worth warning you about, it is worth
> fixing. So in effect there is nothing different between a warning and an
> error.
>
> I do not support this philosophical opinion. I tend to think that giving
> more freedom of expression to coders is better than nannying them. In other
> words, I think we should let coders choose the type of dangers they are
> willing to be responsible for. Give coders warnings, if that's what they
> ask for, and keep quiet, if that's what they ask for. And only issue an
> error if the compiler cannot achieve a valid object code output.
>
> A compiler is a tool to assist coders.
>
I think we're just lucky to have warnings in DMD period. Hell practically DID freeze over when Walter implemented warnings into his compiler.
Any further disparagement about the implementation might see them removed altogether. ;-)
-JJR
|
December 07, 2005 Re: About DM's Warnings | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Reimer | On Tue, 06 Dec 2005 19:16:38 -0800, John Reimer wrote: > I think we're just lucky to have warnings in DMD period. Hell practically DID freeze over when Walter implemented warnings into his compiler. > > Any further disparagement about the implementation might see them removed altogether. ;-) Totally agree. I always compile with -w on, and clean up my code as I go. It is an indispensable feature for me now. -- Derek (skype: derek.j.parnell) Melbourne, Australia "A learning experience is one of those things that says, 'You know that thing you just did? Don't do that.'" - D.N. Adams 7/12/2005 2:18:10 PM |
December 07, 2005 Re: About DM's Warnings | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Reimer | "John Reimer" <terminal.node@gmail.com> wrote
> I think we're just lucky to have warnings in DMD period. Hell practically DID freeze over when Walter implemented warnings into his compiler.
>
> Any further disparagement about the implementation might see them removed altogether. ;-)
Perhaps why it's so rare for anyone to complain about it ;-)
Who ever said we don't know what side the bread is buttered on?
|
December 07, 2005 Re: About DM's Warnings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | Bruno Medeiros wrote: >> This isn't a bug, it's by design <g>. Warnings about unused variables can >> get rather annoying when they're intended. > Why is it that Digital Mars compiler's option to enable warnings does not only warning-notification but also error-on-warning? And there isn't even a way to do just the first? Another thing that is broken about DMD warnings is that they go stdout ? David has patched this up for GDC, to make them go stderr as they should but it hasn't made it "upstream" into DMD - despite several bug reports. It's all just a bunch of "s/printf\(/fprintf(stderr, /", excuse my Perl. --anders PS. There's a related bug, affecting where the exceptions get printed: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/2001 http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/4368 |
Copyright © 1999-2021 by the D Language Foundation