重构的主要目的是,
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
I can only say you come from technical perspective.作者: stgeorge 时间: 21-6-2009 17:34
基本不做refactoring,
重构成本非常大。
首先要有unit testing 支持,unit testing 搭建环境,维护比较费时间。
然后写mock代码,
用CC进行check in build>
成本太高了。
必须要有牛人,才能支持。
而且对team member的要求也非常高。作者: 清风不写字 时间: 21-6-2009 18:48
我们是XP开发方式,经常重构,unit test 都是最初开发就写好的,很少为了重构再写unit test。
代码提交前要在本地运行一遍大部分的单元测试
提交后测试服务器隔几个小时自动进行一遍check in build,并运行全部的测试。
大家习惯了就好了,没感觉重构有多麻烦。作者: yuba 时间: 21-6-2009 19:05
"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"