Re: Unused variables, better as error or warning?

2010-08-21 Thread Pelle
On 08/20/2010 08:53 PM, Jonathan M Davis wrote: On Friday, August 20, 2010 11:35:48 Nick Sabalausky wrote: bearophilebearophileh...@lycos.com wrote in message news:i4luk9$2rd...@digitalmars.com... A small Reddit thread regarding if unused variables and imports are better as errors or

Unused variables, better as error or warning?

2010-08-20 Thread bearophile
A small Reddit thread regarding if unused variables and imports are better as errors or warnings: http://www.reddit.com/r/programming/comments/d3emo In my opinion in this case errors are too much, warning are enough. Few situations for those warnings: - warning for unused variables (as GC, C#

Re: Unused variables, better as error or warning?

2010-08-20 Thread dsimcha
== Quote from bearophile (bearophileh...@lycos.com)'s article A small Reddit thread regarding if unused variables and imports are better as errors or warnings: http://www.reddit.com/r/programming/comments/d3emo In my opinion in this case errors are too much, warning are enough. Few situations

Re: Unused variables, better as error or warning?

2010-08-20 Thread Pedro Rodrigues
I agree, unused variables should be treated as warnings. In my opinion, warnings should be employed only in situations where the compiler detects that the programmer might have made a mistake, but which are not impeditive of compiling and running the program. Having unused variables clearly

Re: Unused variables, better as error or warning?

2010-08-20 Thread Andrej Mitrovic
I think I've read somewhere (either the spec or TDPL) that states unused variables are errors. But I don't agree with that. Make it a compiler flag if it's really needed. A warning is ok for me. If I'm just trying out some code, I might use one or another variable while declaring both. If I only

Re: Unused variables, better as error or warning?

2010-08-20 Thread Simen kjaeraas
dsimcha dsim...@yahoo.com wrote: If we make unused imports an error, how is anyone supposed to do import someSmallLibrary.all? If you make unused imports an error, the collective cost of extra import declaration boilerplate will probably be larger than the GDP of some African countries.

Re: Unused variables, better as error or warning?

2010-08-20 Thread bearophile
Something I was forgetting, I have an open enhancement request about this, by the way: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Bye, bearophile

Re: Unused variables, better as error or warning?

2010-08-20 Thread Nick Sabalausky
bearophile bearophileh...@lycos.com wrote in message news:i4luk9$2rd...@digitalmars.com... A small Reddit thread regarding if unused variables and imports are better as errors or warnings: http://www.reddit.com/r/programming/comments/d3emo In my opinion in this case errors are too much,

Re: Unused variables, better as error or warning?

2010-08-20 Thread Jonathan M Davis
On Friday, August 20, 2010 11:35:48 Nick Sabalausky wrote: bearophile bearophileh...@lycos.com wrote in message news:i4luk9$2rd...@digitalmars.com... A small Reddit thread regarding if unused variables and imports are better as errors or warnings:

Re: Unused variables, better as error or warning?

2010-08-20 Thread Andrej Mitrovic
Yes there are, you enable them with -wi, which are informational warnings. Some errors are listed here, but I'm not sure which of these can be used with -wi: http://www.digitalmars.com/d/2.0/warnings.html On Fri, Aug 20, 2010 at 8:53 PM, Jonathan M Davis jmdavisp...@gmail.com wrote: On

Re: Unused variables, better as error or warning?

2010-08-20 Thread Jonathan M Davis
On Friday, August 20, 2010 06:06:17 bearophile wrote: A small Reddit thread regarding if unused variables and imports are better as errors or warnings: http://www.reddit.com/r/programming/comments/d3emo In my opinion in this case errors are too much, warning are enough. Few situations for

Re: Unused variables, better as error or warning?

2010-08-20 Thread KennyTM~
On Aug 21, 10 02:53, Jonathan M Davis wrote: On Friday, August 20, 2010 11:35:48 Nick Sabalausky wrote: [snip] An error would be an enormous pain in the ass. A warning might be helpful in some cases. Except that thanks to how warnings are deal with in dmd, there's not much difference

Re: Unused variables, better as error or warning?

2010-08-20 Thread Walter Bright
Jonathan M Davis wrote: I'm sure that there are cases where it would be nice for the compiler to point out that you're uselessly assigning to a variable (especially if you're making a useless function call too), but it would cost the compiler too much in complexity and cost the programmer in

Re: Unused variables, better as error or warning?

2010-08-20 Thread Nick Sabalausky
KennyTM~ kenn...@gmail.com wrote in message news:i4mk20$306...@digitalmars.com... On Aug 21, 10 02:53, Jonathan M Davis wrote: On Friday, August 20, 2010 11:35:48 Nick Sabalausky wrote: [snip] An error would be an enormous pain in the ass. A warning might be helpful in some cases.

Re: Unused variables, better as error or warning?

2010-08-20 Thread Jonathan M Davis
On Friday 20 August 2010 12:01:54 Andrej Mitrovic wrote: Yes there are, you enable them with -wi, which are informational warnings. Some errors are listed here, but I'm not sure which of these can be used with -wi: http://www.digitalmars.com/d/2.0/warnings.html I missed that. Thanks for the

Re: Unused variables, better as error or warning?

2010-08-20 Thread KennyTM~
On Aug 21, 10 03:35, Walter Bright wrote: Jonathan M Davis wrote: I'm sure that there are cases where it would be nice for the compiler to point out that you're uselessly assigning to a variable (especially if you're making a useless function call too), but it would cost the compiler too much

Re: Unused variables, better as error or warning?

2010-08-20 Thread bearophile
Walter Bright: Having such be errors (or warnings) makes for a very annoying experience. For example, when you're commenting out code trying to find a problem, or when you're generating D source code from some DSL, etc., having unused variables or assignments happen often. In this answer

Re: Unused variables, better as error or warning?

2010-08-20 Thread bearophile
Jonathan M Davis: I have seen you have commented in the enhancement request too, thank you for your answers. I agree with #1, #3, and #4 but not #2. It requires control flow analysis to get that to work, and Walter generally avoids that. The situation here is different. Walter was opposed

Re: Unused variables, better as error or warning?

2010-08-20 Thread Walter Bright
bearophile wrote: So if you give me this warning, you are free to keep it always deactivated in all your future D programs :-) I detest warnings because they make the language rules fuzzy. Code should be legal or illegal. Wishy-washy warnings make code non-portable because different

Re: Unused variables, better as error or warning?

2010-08-20 Thread Jonathan M Davis
On Friday, August 20, 2010 14:12:09 Walter Bright wrote: bearophile wrote: So if you give me this warning, you are free to keep it always deactivated in all your future D programs :-) I detest warnings because they make the language rules fuzzy. Code should be legal or illegal.

Re: Unused variables, better as error or warning?

2010-08-20 Thread bearophile
Walter Bright: I detest warnings because they make the language rules fuzzy. Code should be legal or illegal. Wishy-washy warnings make code non-portable because different compilers implement different warning. I remember this problem you have explained in past. In normal C code (not

Re: Unused variables, better as error or warning?

2010-08-20 Thread Jonathan M Davis
On Friday, August 20, 2010 14:06:49 bearophile wrote: Jonathan M Davis: I have seen you have commented in the enhancement request too, thank you for your answers. I agree with #1, #3, and #4 but not #2. It requires control flow analysis to get that to work, and Walter generally avoids

Re: Unused variables, better as error or warning?

2010-08-20 Thread bearophile
Jonathan M Davis: The compile must be just as accurate when dealing with warnings as when dealing with errors. Nope. If your language (like C#) specs say that uninitialized variables are not allowed, the compiler has to catch them all and report them as errors. If your language (C, D, etc)

Re: Unused variables, better as error or warning?

2010-08-20 Thread Walter Bright
bearophile wrote: On the other hand, in a hairy C program of mine I have defined a counter variable, and then I have forgotten to use it, the unused variable warning given by GCC has given me a hint, and I have quickly fixed the code in few seconds. Not every problem is worth using a

Re: Unused variables, better as error or warning?

2010-08-20 Thread Jonathan M Davis
On Friday, August 20, 2010 15:11:35 bearophile wrote: Jonathan M Davis: The compile must be just as accurate when dealing with warnings as when dealing with errors. Nope. If your language (like C#) specs say that uninitialized variables are not allowed, the compiler has to catch them all

Re: Unused variables, better as error or warning?

2010-08-20 Thread bearophile
Walter Bright: Not every problem is worth using a sledgehammer to deal with. Giving a warning where you have not used a variable is not a sledgehammer, it's a light thing, that helps keep code tidy and once in a while helps avoid bugs. I have not your experience with the troubles caused by

Re: Unused variables, better as error or warning?

2010-08-20 Thread div0
On 20/08/2010 22:28, Jonathan M Davis wrote: On Friday, August 20, 2010 14:12:09 Walter Bright wrote: Warnings are good for things which you _should_ fix but don't have to immediately No they aren't. Warnings are good for exactly nothing. Warnings suck massive arse, hide geniune problems

Re: Unused variables, better as error or warning?

2010-08-20 Thread Walter Bright
bearophile wrote: Walter Bright: Not every problem is worth using a sledgehammer to deal with. Giving a warning where you have not used a variable is not a sledgehammer, it's a light thing, that helps keep code tidy and once in a while helps avoid bugs. My point is it is not a light thing.

Re: Unused variables, better as error or warning?

2010-08-20 Thread Walter Bright
bearophile wrote: If your language (C, D, etc) allows you to not use a variable the last time you have initialized it, and then you want to add a warning that finds such situations, you don't need the compiler to be 100% accurate, even if some of such situations are not detected then it's

Re: Unused variables, better as error or warning?

2010-08-20 Thread Leandro Lucarella
Walter Bright, el 20 de agosto a las 14:12 me escribiste: bearophile wrote: So if you give me this warning, you are free to keep it always deactivated in all your future D programs :-) I detest warnings because they make the language rules fuzzy. Code should be legal or illegal. Wishy-washy

Re: Unused variables, better as error or warning?

2010-08-20 Thread Leandro Lucarella
dsimcha, el 20 de agosto a las 13:42 me escribiste: == Quote from bearophile (bearophileh...@lycos.com)'s article A small Reddit thread regarding if unused variables and imports are better as errors or warnings: http://www.reddit.com/r/programming/comments/d3emo In my opinion in this

Re: Unused variables, better as error or warning?

2010-08-20 Thread bearophile
Leandro Lucarella: Fortunately there are other compilers :) Regarding this I have appreciated few features of LDC that make it more practical for real usage, as the pragma(allow_inline) and few other practical-oriented things. Bye, bearophile