博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Checkstyle, PMD, Findbugs对比
阅读量:4199 次
发布时间:2019-05-26

本文共 3656 字,大约阅读时间需要 12 分钟。

当人们谈及代码规则引擎时。每个人都喜欢站在自己的位置上说自己较为喜欢的工具,而排斥其他的工具。

 For instance, a PMD supporter could say :

“ is a stupid tool consuming time to search for tab characters when is a smart one that can do the job alone as a good soldier, is very good for resource consumption and is … uh, what is Macker ? “
Time to breathe ! There is in fact no need to take such position since those tools are not competing but are complementary and should be used simultaneously as it is the case in . Each of them is mainly targeting a certain type of coding rules : conventions (Checkstyle), bad practices (PMD) and potential bugs (FindBugs).
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 !

What’s about ? Whereas Checkstyle, PMD and Findbugs focus their attention on analyzing sources and applying rules, Macker takes a big step back to identity architectural issues. Here are few examples of architectural rules :

  • Classes in the UI layer may not directly access the data object layer, or use classes in java.sql
  • External systems may not access internal implementation classes (suffixed with ‘Impl’)
  • One functional module may access another only through its API
  • Only classes implementing interfaces in javax.ejb, and certain framework packages, may use the EJB APIs

Macker looks at your application in the same way a man on the moon looks at earth : hey guys, what is happening ? Pacific ocean is too close to European continent ! Once you have a clear idea of what your architecture should look like, you can easily model it with Macker to keep your architecture consistent over time. With Macker you can define architectural conventions and identify architectural bad practices.

转载地址:http://evbli.baihongyu.com/

你可能感兴趣的文章
在中国提供了60亿次服务的疫情模块向世界开源
查看>>
世界卫生组织与腾讯加深合作 新冠肺炎AI自查助手全球开源
查看>>
Hibernate 中get, load 区别
查看>>
java反射详解
查看>>
JPA 注解
查看>>
JQuery 简介
查看>>
Java创建对象的方法
查看>>
Extjs自定义组件
查看>>
TreeGrid 异步加载节点
查看>>
Struts2 标签库讲解
查看>>
Google Web工具包 GWT
查看>>
材料与工程学科相关软件
查看>>
MPI的人怎么用仪器
查看>>
windows 下AdNDP 安装使用
查看>>
Project 2013项目管理教程(1):项目管理概述及预备
查看>>
ssh客户端后台运行
查看>>
哥去求职,才说了一句话考官就让我出去
查看>>
【React Native】把现代web科技带给移动开发者(一)
查看>>
【GoLang】Web工作方式
查看>>
Launch Sublime Text 3 from the command line
查看>>