Advertisement
The Quality Code
Judging the quality of software can be based on different aspects. The first is functional quality: does the software behave as it is supposed to do. To assess this, methods, tools and frameworks are available. Another aspect on which the quality of software code can be judged is structural quality: is the software designed and implemented in a correct way with the use of design patterns.

For the assessment of the structural quality, there are also tools available to aid the developer. These tools can warn when suspicious statements are used, and give insight in the interdependencies between classes and components. Commonly made errors in statements are called bug-patterns. Errors in the interdependencies between classes and components are called anti-patterns.

The first tool that is capable of detecting bug-patterns is the Java compiler. Fortunately, the java compiler is reasonably strict. A c-compiler will only warn for an non-initialized variable, the java compiler considers this to be an error. Also the fact that the handling of exceptions is compulsory is a benefit. Languages like C# doesn’t enforce this. According to the designer of C# it is more productive not to have to handle exceptions all the time. You can discuss about the benefits of both implementations, but from the point of view of structural quality one prefers the compulsory way of Java.  As of version 1.5 it is also possible to let the compiler show more information by using the –Xlint switch.

A more specialized tool to look for bug-patterns is FindBugs. A simple example of a bug-pattern is the creation of a String with the statement new String(“foo”). In the worst case this statement will result in the creation of 2 objects. FindBugs finds these statements and suggests ways to prevent the use of the bug-pattern. The list of possible bug-patterns recognized by FindBugs is quit long. Unfortunately, the number of false alarms FindBugs produces is also considerable, although the developers are proud to announce this amount will be less than 50%. The benefits are nevertheless enormous. This tool can be used in an incidental way during the development of new software or on a more regular base via an ANT task, the same way as, for example,  JUNIT test. 

Other tools can be used to gain insight in the structure of a program as a whole. One of these tools is Structural Analysis for Java (SA4J). This tool visualizes interdependencies between classes, packages and components, and looks for anti-patterns. An example of an anti-pattern is a so-called butterfly. A lot of classes will need to be adapted as a result of a change in a butterfly class. Not only tells this something about the structural quality of the code, SA4J can also show the impact of a change. 

 SA4J is capable of visualizing the structure of a program in a fancy way. Unfortunately, if it reports many serious anti-patterns it will be to late to improve the structural quality by making some minor adjustments. When a support organization needs to assess the risks of supporting some new program, SA4J can be a big help. It’s also a valuable tool when one needs to make an impact analysis for a request of change. FindBugs is another cup of soup. Tools like this should be used in every project on a regular basis. The recommendations produced by this tool are small enough to implement without any risk, and really help to increase the quality of the code.

Interesting links: 

leo blommers jaava polis newsletter.jpgAuthor: Leo Blommers
Finalist IT Group (The Netherlands)
email: , tel. +31 10 217 08 00


© 2000-2007 Finalist IT Group BVIAll rights reservedIinfo@finalist.com