Unused variables, better as error or warning?
Pelle
pelle.mansson at gmail.com
Sat Aug 21 06:12:14 PDT 2010
On 08/20/2010 08:53 PM, Jonathan M Davis wrote:
> On Friday, August 20, 2010 11:35:48 Nick Sabalausky wrote:
>> "bearophile"<bearophileHUGS at lycos.com> wrote in message
>> news:i4luk9$2rdg$1 at 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, warning are enough.
>>>
>>> Few situations for those warnings:
>>> - warning for unused variables (as GC, C# and other compilers do);
>>> - warning when a variable get used in some ways, and then its last
>>> assignment gets unused (done by a kind of C compiler);
>>> - unused imports (useful to keep code clean and remove unnecessary module
>>> dependences);
>>> - unused functions (but this is harder to do in a clean way in a language
>>> that has templates, so this may be omitted).
>>>
>>> Among those four warnings the most useful are the first two ones. In C
>>> once the unused variable warning of GCC has found at compile time a bug
>>> in my code (I did forget to increment that variable in the loop). So I
>>> have loved this warning ever since.
>>
>> 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 between an error and a warning; it's just a question of how picky you
> want to be about errors. As it is, I'd argue that there is no such thing as a
> real warning in D. You never see warnings unless you use -w, at which point
> they're treated as errors. And if you're being at all careful, you're going to
> be compiling with -w, so it doesn't make much difference. You can choose to
> compile without -w until you think what you have works and then use -w to find
> stuff you missed, but then you could easily be being shot in the foot by
> something that's considered a warning. If you had seen it, you could have dealt
> with it. What dmd needs is for warnings to be visible in normal compilation,
> making -w only make warnings errors as opposed to being the way to make them
> appear as well. As it is, warnings pretty much might as well be errors.
>
> - Jonathan M Davis
I don't get this point of view.
I mean, either you care about them, in which case they may as well be
errors, or you don't care, in which case you don't need to see them at all.
When you insert a debug-ish early return, do you really want to see the
warning text every time you compile?
I think what dmd does is great. :-)
More information about the Digitalmars-d
mailing list