There has been a lot of Java code landing in mozilla-central lately. I
was wondering what people think of defining Mozilla style and coding
guidelines for Java and then empowering people to enforce these through
tools.
Currently, the best we seem to have is a wiki entry [1] and we leave it
up to the review process to catch transgressions. This is a good start.
But, no matter how good of a reviewer you are, you'll never been as good
as a dedicated tool. Besides, as a reviewer, you should be using your
brain cycles on assessing the quality of code, not compiling it.
I think we can do better. I'm not sure what others will think, but here
is my proposal to get the conversation started:
1) Create "blessed" configurations for popular tools like Checkstyle [2]
2) Add these configurations to mozilla-central and hook up build targets
so they can be executed easily. Run them by default during builds (when
it makes sense) to raise awareness of violations (much like compiler
warnings aren't hidden during silent builds). Perhaps they are disabled
on the build farm initially because it would be a lot of work/overhead
to deploy them. But, they would eventually run during all builds.
3) Encourage action from tool output (likely enforced through review
process)
4) Tailor the configurations to our liking over the coming weeks/months
5) Down the road, establish a flag day where builds go orange if the
automated analysis produces unacceptable errors. Many tools allow you to
assign a severity to a transgression. We can initially narrowly define
the "orange set" so there is little pain to initially enable build failures.
6) Over time, gradually make the policies more strict and fix warnings
as we go. One idea would be to bump up the strictness of each warning
type in each release cycle until all warnings cross the threshold and
cause build failures.
7) Arrive at a state where we are happy with the strictness and there
are no static analysis warnings [and the code is more uniform and less
bug-prone].
One thing to note is that most Java tools allow you to suppress warnings
on a line, file, or package level, much like how C/C++ compiler warnings
work with #pragma or CLI flags, so it is likely no policy would be
totalitarian. You do pay a small price for working around them, but I
personally think a reminder before you break the law is a good thing.
While this could apply to other languages in the tree, I'd like to limit
the discussion to Java because a) there isn't much Java in the tree and
thus the problem is more manageable b) there are a bunch of new-to-Java
coders who would probably benefit significantly from static analysis
assistance c) the tools for Java are great (probably the best of any
language).
Thoughts?
[1]
https://wiki.mozilla.org/Fennec/NativeUI/CodingStyle
[2]
http://checkstyle.sourceforge.net/