Who even wrote this code??!
Hello again,
This week it’s all about refactoring again. Instead of using a pattern or principle we are using metrics to detect problems in our codebase.
To collect metrics, we are using our self hosted version of SonarQube.
Our two main code bases are linked to projects in SonarQube, this way everytime we push code to GitHub the code gets analysed, and we can get feedback about our new code.
You can see the pipeline here:
GitHub
Now we want to take a look at interesting metrics.
First looking at this chart.
One can see we have two spikes in duplicated code, that we could refactor. Therefore we did that in both the commit here and here.
Now let’s look at a combination of metrics.
We want to see how the cognitive complexity and the lines of code fit together.
The cognitive complexity describes how complex a function is to understand when reading it. Basically, it implies that low cognitive complexity leads to better readability and maintainability.
You can note how the two metrics fit together in the chart here.
NOTE: The upper line is showing the lines of code, the lower one the cognitive complexity.
Looking at the chart our cognitive complexity increases with the lines of code, which is not perfect. In our case we have a problem with complex functions that are too long to understand properly. A reason for this is that the required logic for many endpoints is itself very complex and there are many edge cases to cover. Each edge case has to be caught with an if block which increases the complexity.
Furthermore, the way the logic of the project is written is not good. Endpoint logic share a lot of logic which is not implemented once but is rather reimplemented in each endpoint. This also leads to more edge cases and things that need to be caught.
Refactoring this would mean to basically rewrite the whole backend, which is something we will have to perform at some point.
Therefore, we are not fixing this problem right now because our focus is on implementing the remaining use cases.
Have a great week.
FileFighters
Leave a comment on our blog:
Comment on our blog below or open an issue on our Github repository.