Enable the early detection of harmful trends
Enable the early detection of harmful trends
Sonargraph-Enterprise is designed to allow stake-holders to track important software quality metrics over time. The idea is that this would enable the early detection of harmful trends so that issues can be fixed while they are still easy to fix. The metrics displayed by Sonargraph-Enterprise can be fully customized by the user. However, in this article I will explain the “default” profile that comes with a set of preselected metrics that cover important aspects of code health and quality.
When you navigate to Sonargraph-Enterprise in your browser, that first thing you will see is a list of all projects that have uploaded data to Sonargraph-Enterprise. To add a project to this list you need use Sonargraph-Build to upload a set of data typically once a day. The details are described in the Sonargraph-Build manual.
As you can see for each project we display the name, organizational unit and owner, the date of the last update and two metrics that are compared over a configurable number of days. The default would be 90 days, but can be changed by defining a new profile. By clicking on any column header you can sort the list by the values in that column. A second click will reverse the sort order.
In the default profile we decided to use “Maintainability Level” (ML) and “Lines of Code” (LoC). ML is a relatively new metric that we designed together with some of our customers to measure the overall maintainability of a software system by analyzing the dependency structure. We have published a blog article that describes how the metric is calculated in detail. In short it is a percentage value with 100% marking the best possible value. You should be concerned if it falls below 50% and aim to keep it above 70%. In the list above you can see that the project “hibernate-core” scores under 7%. If you get that low it will be very difficult to bring the value back up because you have reached the final stages of a big ball of mud. On the system level the metric is calculated as a weighted average of the ML values of all the modules in a system.
Sonargraph-Enterprise allows you to establish a metric-based feedback loop. You can follow trends and react if metrics turn yellow or red. The earlier you do that the less effort will be needed to address the problem.
The second metric “Lines of Code” is obvious. It tells you how big a system is and how much changes are happening.
Once you click on one of the systems you will get a more detailed view with 10 different metrics:
You see two blocks which we call metric sets. These sets are configurable, but in that case they are pre-configured s part of the default profile. On the right side you see how the currently selected metric in the set changed over time The default time window is 90 days, but also can be changed by creating a new profile.
Lets go through the first metric set called “Key Metrics”:
The second metric set is focussing on cyclic dependencies (as the name implies). A cyclic dependency is created when two source files mutually depend on each other. This would form the smallest possible cycle group of two elements. Of course those cycle groups can grow. The reason why “hibernate-core” has such a low value of ML is caused by a gigantic cycle group of more than 1,000 Java files.
This graphic shows a dependency graph where the circles could be either single source files or packages or name spaces. We have two cycle groups there, one in red and one in gray.
Detecting and analyzing cyclic dependencies is a very reliable method to detect the level of structural or architectural erosion in a software system. In short, the bigger the cycle groups and the more elements are involved in those cycles, the bigger the problem is. Smaller cycle groups are less harmful then larger cycle groups. When looking at cycles between source files or classes it is preferable to have them all within the same package or name space. Large cycle groups are a good indicator for discovering software rot.
There are plenty of reason why cyclic dependencies, especially larger cycle groups are harmful for software maintainability:
Structural/architectural erosion is caused by these cyclic dependencies and can be considered the most toxic form or technical debt. The reason is that fixing an eroded structure requires global refactorings of the code base, which is risky and takes a lot of effort. Other forms of technical debt are much more localized and can therefore be fixed by local changes.
Therefor this second metric set focusses on that particular aspect. We don’t even have to look at conformance to architectural models. But we can assume that if the values are good the team has a good handle on the overall architecture and structure of the system. And having an architectural model based on Sonargraph’s architecture DSL will automatically ensure that your system can never erode into a big ball of mud. I highly recommend to make the creation of such models mandatory for each development team.
Now lets look in the metrics in that set:
Relative cyclicity is calculated by first adding up the cyclicity of all cycles groups in a given scope (system or module – in Sonargraph terms a system can contain many modules, at least one). The cyclicity of a cycle group is the square number of the number of elements in the group. For example the cyclicity of a cycle group with 4 elements is 16.
This leads us to the formula for relative cyclicity:
Lets try that formula with a hypothetical example. Lets assume we have a system with 50 source files, all of which are involved in one big cycle group of 50 elements. In that case “sumOfCyclicity” would be 2.500 (50 * 50). The square root gives a value of 50, which will then be divided through the total number of elements in that system, in our case 50. So relative cyclicity would be 100%, the worst possible value.
Now lets assume a similar system with 50 source files, but instead of one big cycle of 50 elements we have 25 cycles of 2 elements. In that case the “sumOfCyclicity” would be 100 (25 * 4). In that case the formula would evaluate to 20%.
Now we can see the usefulness of that metric. Even though all source files in both examples are involved in cyclic dependencies, the second value is much better caused by the fact that you could cut the second system into 25 individual parts, while the first system cannot be sub-divided since everything is in one big cycle.
Thank you for reading this article to the end.