Despite our best intentions, many of us don’t always get to work on the latest and greatest language or technology. In some cases, we may need to make our way around a code base that has been written by another team. Given that the average software system lives for 11 years, it’s probably safe to say that there are, in fact, many such cases where we need to quickly assess a new code base to find its flaws (i.e. risks) and determine which portions of the code may be difficult to maintain and extend and which should be easier. If you’re looking at a code base that was developed by another team or even code you just wrote yesterday, once it’s written, it’s now code that you must maintain.
If you need to analyze a code base and determine which portions of the code are more risky than others, what would you do? For me, I use tools that help me quickly assess the code quality. For instance, I’d like to know something I call the “big five” measures:
- Code complexity
- Amount of duplication
- The resilience of the architecture
- Whether coding standards are being applied
- Amount of test code coverage
As I mentioned, I like to use tools to help me assess these measures. However, there are sometimes concerns when people consider using code metrics on their projects:
1) Don’t know which tools to use
2) Can be easily abused
3) Not sure what the data means
The table below links a measure to a tool (.NET and Java), the code smell associated with this measure, the refactoring for the smell and possible patterns that may be applied to refactor the code smell.
| Measure | Smell | Tools | Refactoring | Pattern |
|---|---|---|---|---|
| Cyclomatic Complexity | Conditional Complexity | IDE, CCMetrics, Source Monitor, JavaNCSS, Eclipse Metrics | Extract Method, Extract Class, Replace Conditional with Polymorphism | Abstract Factory, Strategy |
| Number of Lines in Method | Long Method | IDE, PMD, Eclipse Metrics, CheckStyle, Source Monitor, FxCop | Extract Method | Strategy |
| Depth of Inheritance (DIT) | IDE, PMD, Source Monitor | Replace Inheritance with Delegation, Pull Up/Push Down Method | Delegation |
This is not a detailed list, but should give you some ideas. I plan to add to this list in the future. Do you have additional measures|tools|refactorings|patterns? Please share them with us.
Next time you need to target risky parts of your code base, use these tools to obtain metrics so that you can monitor and improve your code quality (through refactoring and patterns) throughout your development lifecycle.

December 15th, 2006 at 10:19 am
IntelliJ replace the most of this tool
December 16th, 2006 at 1:27 pm
Yes, IntelliJ/IDEA, Eclipse and other IDEs provide this type of support. As I mentioned in
Remove the smell from your build scripts:
http://www-128.ibm.com/developerworks/java/library/j-ap10106/index.html, that while using an IDE for static/dynamic analysis is definitely valuable (and highly encouraged), it shouldn’t be your only tool for performing this analysis. This is because it locks you into an IDE — especially if you’re on a project that uses multiple IDEs (which seems to be the norm). In any case, the tool itself (as long as you have some tool) doesn’t matter as much as whether you are performing this type of analysis throughout the development lifecycle and have techniques (refactorings, patterns, etc.) to improve the code. Btw, I will add a generic “IDE” to the table which we’ll presume to mean “IntelliJ, Visual Studio, Eclipse, etc.”. Thanks!