与自动代码检查工具“结对编程”Pair Programming with PMD

AutoAsm hp 技术经理  2011-09-19 05:24:57
http://blog.csdn.net/autoasm/article/details/6790838


Pair Programming with PMD
分类: 工程与管理 2011-09-19 17:10 2人阅读 评论(0) 收藏 编辑 删除
The Cost of Pair Programming

As you guys have known, Pair programming is one of most important best practice of Extreme Programming and other agile software approaches. It can reduce bug rate significantly, it also has positive impact on improvement of programming skill, but the cost of pair programming is, boss have to hire more programmers to work together. Due to the finance concern, very few boss and orgnization adopt pair programming as their best practice.

In fact, an variant of pair programming can be used in very LOW cost. Programmers can "pair programming" with code checking tools, instead of human being programmer. In other words, we can programming with "robot" programmer.
What's PMD

PMD is a powerful static code checker for Java language, I don't want give a long definition here, because Wiki has gave a clear one.

PMD is a static ruleset based Java source code analyzer that identifies potential problems like:

Possible bugs - Empty try/catch/finally/switch blocks.
Dead code - Unused local variables, parameters and private methods.
Empty if/while statements.
Overcomplicated expressions - Unnecessary if statements, for loops that could be while loops.
Suboptimal code - Wasteful String/StringBuffer usage.
Classes with high Cyclomatic Complexity measurements.
Duplicate code - Copied/pasted code can mean copied/pasted bugs, and decreases maintainability.

Why PMD

As mentioned in last sector, PMD is a static code checker can detect potential program in java source code. There are lots of similar tools in open source community, but PMD has its own competitive advantage.

Easy to Get
Easy to Use
Powerful
Customizable
Document and support

findbugs (http://findbugs.sourceforge.net/) is an alternative powerful static check tools, if you don't like PMD.
How to use PMD

PMD has provide plug-in for eclipse. It help you to detect and fix potential issues in workspace with GUI support.

This page give a brief but clear instruction on installing of eclipse plugins.

http://pmd.sourceforge.net/eclipse/

Once you complete the installation, you can check your code with context menu of PMD plugin.

1. Switch to PMD perspective

2. Select a java file you want to check

2. Right click mouse, select PMD->Check code with PMD.

PMD list violations in both outline window and Text editing box if it found some violations in your source code. Violations be assigned different level, some of them are critical while others are not. Usually we should focus on at least critical issues.
Conclusion

PMD can support us to find potential problems, bad practices and methods that has too much complexity. Programming skill of programmer also can be improved with PMD because programmers can know what bad practice is. In general, PMD can help software team to reduce defect rate and improve productivity.
References

1. http://en.wikipedia.org/wiki/Pair_programming

2. http://en.wikipedia.org/wiki/Extreme_Programming

3. http://pmd.sourceforge.net/

4. http://findbugs.sourceforge.net/
...全文
79 点赞 收藏 回复
写回复
回复

还没有回复,快来抢沙发~

发动态
发帖子
研发管理
创建于2007-08-27

772

社区成员

2.8w+

社区内容

软件工程/管理 管理版
社区公告
暂无公告