Given that the concept of "best" and "worst" practices can be different in different environments, our company introduced a standard set of internal "best" practices that are continuously violated by our developers. I want to share two in particular:
- Never handle exceptions with
ex.printStackTrace()
, instead log them - Never use
System.out
in a web application for debugging purposes, better use debug log
These two are fairly simple to detect as a simple Search command can display each violation.
I'd like to ask if anything can be done to prevent the coder from using these prohibited methods in his projects. Forcefully deprecating the System.out
object or the printStackTrace
method from out of the standard JVM would be a great idea as provides evidence of the mistake in the form of a warning.
Since we don't implement a human code review mechanism (code is reviewed only when issue arise, or a new developer takes charge of a module), I'm seeking for automated ways of preventing such common mistakes, including breaking the compilation itself. I'm thinking about something like a Java plugin in which I can configure special rules for what that is not an error in Java syntax to be considered as an error. ReSharper plugin for Visual Studio, for example, does a similar thing when dealing with naming and coding conventions.