Rhino said:
I suppose this is a rather odd question but how many warnings is too many
when you are using a Java compiler like the one in Eclipse 3.1.1?
87. 86 is just barely passable, 85 is okay. But once you've got 87, you
know you have problems.
Using the default settings for the 1.5 compiler in a fresh install of
Eclipse 3.1.1, my various projects have over 4000 messages between them,
22 of which are 'errors' that I have yet to repair. The rest are warnings
of one kind or another. I could decrease this number substantially by
either setting many conditions to 'error' or 'warning' when they are
currently 'ignore' or increase it substantially by setting 'ignore'
conditions to 'error' or 'warning'. And, of course, I could probably make
the vast majority of them go away simply by rewriting code.
I've got 15058 warnings in my current Eclipse workspace. The settings of
what are considered warnings and what aren't vary from project to project.
"Externalized Strings" is turned off everywhere, I think.
Some of my code is machine generated, so I can't just go in and fix the
warnings. I have to change the code-generator so that the code it generates
no longer generates warnings. Except the code-generator itself is generated,
so I can't directly edit that either.
That's my excuse for having 15058 warnings. When I'm programming at
home, for fun, none of my code is generated, and there's probably 0 warnings
right now, though it occasionally does reach the single non-zero digit
range. And I try to turn all the warnings on, except sometimes I get lazy,
and turn "externalized strings" off.
The only time I use "@SuppressWarning" is for those "impossible to
avoid" situations with generics, and I accompany the annotations with a
comment explaining why I believe that the warning is unavoidable.
Unfortunately, @SuppressWarning seems to work on a whole method, instead of
on a particular warning, so I occasionally have to remove them to make sure
I didn't introduce new warnings without my realizing it.
I'd be surprised if anyone turned _all_ conditions to 'warning' or 'error'
and then fixed every single one of the warnings and errors so that the
entire workspace was error-free but maybe I'm wrong. That's why I'd like
some feedback on just how many errors and warnings is considered okay and
what is considered excessive.
Surprise!
To put it another way, if you were considering hiring me to write Java for
you and asked me for an example of a completed project to inspect, what
conditions would YOUR compiler be set to detect and ignore and how many
errors and warnings would you consider acceptable? I'm going to guess that
the number of errors should always be zero in a completed project -
correct me if I'm wrong - but that some warnings would be tolerated, on
the theory that fixing every conceivable minor warning is not required to
prove that you write good code. Am I close?
For what it's worth, when I got this job, they never asked me anything
about my philosophy on warnings. On the other hand, they did give me a
(simple) programming problem and asked me to solve it, so they got to see
what kind of code I wrote. Maybe they combed it for warnings, maybe they
didn't. At any rate, the code I gave them had zero warnings with the default
warning/error/ignore settings they had on the workstation they were testing
me on.
Also, errors should almost always be zero, as the javac compiler will
refuse to compile code with errors. Eclipse seems to be able to compile code
with errors (I believe it just replaces the erroneus block with boilerplate
code which just throws an exception), so it's conceivable there might be
shops out there who are willing to tolerate errors in an Eclipse
environment.
Also, when you're compilation tools, sometimes things that one tool
(e.g. javac) considers an error is not to be considerd an error by another
tool (e.g. your inhouse compiler), so there are cases there where errors
might be okay too.
Can anyone give me guidelines to help me determine just what warnings I
should never tolerate and which I should feel free to ignore without
making me look like a bad coder?
I think "number of warnings" is not where you should focus your concern.
For every setting in Eclipse, do you understand what the warning associated
with it means? Could you explain it to another programmer?
- Oliver