重构的主要目的是,
1,消灭duplicated code,因为这是bug隐患之一,support team常常修掉了某处的bug,但是因为在另外的地方还有同样的复制代码。即使找到了复制代码,也增加了维护的cost。
2,premote loose coupling, program to interface。这些措施增强了系统的flexibility,降低来将来的维护cost。
3,refactor to patterns,应用恰当的模式并不一定是立竿见影的效果,但是还是增强了系统的可维护性。
PMD的作用就是分析出代码库的duplicated code,tight coupling,program to implementation等等不良的设计,帮助我们确定好重构的scope,否则,面对成千上万个包,重构将无从下手
PMD scans Java source code and looks for potential problems like:
Possible bugs - empty try/catch/finally/switch statements
Dead code - unused local variables, parameters and private methods
Suboptimal code - wasteful String/StringBuffer usage
Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
Duplicate code - copied/pasted code means copied/pasted bugs
"Code refactoring is the process of changing a computer program's internal structure without modifying its external functional behavior or existing functionality, in order to improve internal non-functional properties of the software"