| Analyst4j - Case Study |
|
|
Measure! To Control.Case Study on using Software Metrics for evaluating code quality and maintainability in Java systems using Analyst4j. PurposeTo evaluate the use of software metrics in ensuring quality and maintainability in Java systems.BackgroundA system under development or maintenance undergoes continuous changes for various purposes. While changes are necessary to meet changing customer needs, ensuring the quality and maintainability of the system prepares the system for further changes without too much effort. Also, on an investment perspective IT systems are expensive to develop and maintain, so ensuring maintainability of the systems gives more longevity and best returns. There is no doubt that people who develop and maintain an IT systems are most important than the actual elements (source code) of a system, but people move on and the only thing that always remains as an asset to the organization is the source code. Therefore ensuring quality of source code also ensures that our best assets have good maintainability.Software metrics collected directly from source code (Internal Metrics) are being put to use to measure various quality attributes of a system. One among the first software metrics is LOC[Source Lines of Code], which is used to measure the effort and subsequently cost of development of a computer program. Research in software measurement grew and now there are more and better choices of metrics to measure effort, cost, complexity, design quality, testability and other quality aspects. However software metrics takes lot of effort to measure, if done manually. Automated software metrics involves analyzing the source code to collect the required measurement, thus giving a jump start to quality analysts with consistent measurement. With measurement process automated we can now focus on understanding the implications of data. IntroductionIn this case study we shall evaluate how metrics can be useful to ensure quality and maintainability of Java systems. The study shall use Analyst4j, a tool which automates most of the industry standard software metrics and provides visualization features to understand the implications of such measurements.Applicable Scenarios1. In house Java systems/products development.When your company is developing Java based products and you as a Quality Analyst or Project Manager would like to measure the quality of code and demonstrate or ensure maintainability of the product being developed. 2. Outsourced Java maintenance. When you have outsourced or subcontracted maintenance/development and you would like to measure the changes, ensure that code entropy is under control and that there is no regression in quality of code. 3. Adopting open source products. When you are evaluating open source products and you want to evaluate whether the system is being well maintained and progressive. 4. In General When you have two or more versions of a Java system and would like understand the changes amongst the versions with the help of software metrics. QuestionsSome of the questions that arises from the above scenario and in quality control initiatives areCase Study CandidateJFreechart is an open source charting solution / component, a highly preferred solution when it comes to charting solution in Java. More details at http://www.jfree.org/jfreechart/We shall take four versions of JFreechart source code for our analysis. 1. jfreechart-0.9.15 2. jfreechart-1.0.1-pre1 3. jfreechart-1.0.1 4. jfreechart-1.0.5 ScopeWe shall analyze the JFreechart source code with Analyst4j and derive answers for our questions with reference to the scenarios mentioned above.Analysis
Preparing the workspace
Analyzing versions of JFreechart source code one by one
Quality Analysis ResultsThe following analysis reports are possible once we complete analyzing all the four version of our case study. General Project Analysis Report Comparison Comparing some of the metrics in the analysis reports of the case study gives us a higher level view of the changes that has gone through the versions. The following table (Table1) represent the changes in our case study.
It can observed that effort (HE) increases with new versions and maintainability(MI) is slightly reducing. However maintainability is way ahead of the guideline threshold of 65, and that maintainability is tolerant considering the change in effort(HE) and NLOC across versions. Measuring Design Changes / Regression We shall attempt to use one ore more automated software metric to evaluate and understand the design changes at different level of code. The levels being Project , Package , Class & Method . Project Level: Amongst other measurements, higher level design changes can be measured by measuring increase / decrease in number of Packages, Interfaces and Max Depth of Inheritance. The following table (Table2) represents these measurements.
It can be observed that
Package Level: To understand package level design changes, a quality analysis graph of number of interface vs number of classes gives instant visibility of changes that has happened across the version.
It can be observed that
Class Level: If design patterns are best practices to be followed during design, antipatterns on the other hand find faulty design patterns. Analyst4j introduced the idea of identifying antipatterns in Java using software metrics, the following graph is an application of the idea to the case study.
It can be observed that
Method Level: One way to understand design changes / regression in methods is to measure its structuredness(Essential Complexity) and complexity (Cyclomatic Complexity). The following graph represents the number of methods whose CC(Cyclomatic Complexity) is greater than 40 and EC(Essential Complexity) > 1. The fundamental in the thresholds being that we want to find structural changes in highly complex methods across versions. Search using metrics Search results across projects graph, shows increase in unstructured code across versions.
It can be observed that:
Measuring Effort Change Project Level: The following table (Table 3) represents list of effort change (using Halstead Effort) across the four versions of our case study.
It can be observed that:
File Level: To understand the change in effort at file level we plot a graph using NLOC Vs Halstead Effort in File, which should reveal file level difference in effort. The following QA graph is generated using Analyst4j represents the change in NLOC and HE for our case study.
We can track the changes in effort in two prominent cases
Class Level: Effort change at class level can be measured using Weighted Methods Per Class, the increase/decrease in WMC would reflect the changes made in a class. The following distribution graph of WMC across the four version of our case study gives us a picture of the changes.
Method Level: The following comparison analysis graph of NLOC Vs Cyclomatic Complexity and Decision Density represent the effort changes across two versions of our case study(jfreechart-1.0.1 and jfreechart-1.0.5). We can track changes in some prominent cases from the above graphs. Decision Density: "draw" method of XYPlot class has increase in decision, "executeQuery" method of JDBCXYDataSet class has remained the same and "drawItem" method of CyclicXYItemRenderer class decision density has reduced. Cyclomatic Complexity: The complexity of "drawSide", "draw" methods of PiePlot3D have remained the same though there has been considerable reduction in NLOC. However the complexity of "draw" method of XYPlot has increased considerably. ConclusionThe case study demonstrates that using software metrics during development or maintenance to evaluate the quality of code is found to be very useful to quickly understand the changes in the code. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Next > |
|---|