Chinaunix首页 | 论坛 | 博客
  • 博客访问: 50782
  • 博文数量: 13
  • 博客积分: 1465
  • 博客等级: 上尉
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-01 10:15
文章分类

全部博文(13)

文章存档

2011年(2)

2008年(11)

我的朋友

分类: Java

2011-06-07 08:41:29

: conventions 

:bad practices 

:potential bugs

The convention type covers naming, comments and format conventions. Here are a few examples :

  • Is there javadoc on public methods ?
  • Is the project following Sun naming conventions ?
  • Is the code written with a consistent format ?

The convention type has often the reputation of being fairly useless as the rules are very simple. How to explain then that most open source projects provide a checkstyle file in their development guide, when the same projects generally throw out anything useless ? It is true to say that the convention rules do not have impact on stability, performance or reliability of an application. However, the convention type is the glue that enables people to work together and to free up their creativity instead of spending time and energy at understanding inconsistent code.



The bad practices type consists of well known behaviors that almost systematically lead to difficulties over time. Here are a few examples of bad practices :

  • Catching an exception without doing anything
  • Having dead code
  • Too many complex methods
  • Direct use of implementations instead of interfaces
  • Implementing the hashcode() method without the not equals(Object object) method

PMD is a kind of angel that always looks over your shoulder to remind you of bad practices, in the same way that your common sense reminds you to iterate with your customer when developing a complete functionality and to answer questions from your coworkers.



The potential bugs type helps you detect what is not clearly visible in the code and understand why sequences of code could lead to potential bugs. Here are a few examples of potential bugs :

  • Synchronization on Boolean could lead to deadlock
  • May expose internal representation by returning reference to mutable object
  • Method uses the same code for two branches

Bugs are like human relations, it is not always easy to understand the problem as there are many parameters to take into account. Can be a good idea to sometimes to see an analyst to help resolve them :-). Findbugs is a kind of analyst for your source code !

阅读(354) | 评论(0) | 转发(0) |
0

上一篇:Practice

下一篇:SWT 透明窗体

给主人留下些什么吧!~~