Developers are constantly juggling between one or the other task. It may seem to be a ‘normal’ thing, but it can harm the software development process. If not measured timely and properly.
There are many metrics that engineering managers can take note of. But, here we will be discussing one of the important yet overlooked metrics in software development – Code Churn.
In this blog, let’s dive deeper into code churn, what causes high code churn, and how you can prevent it:
What is Code Churn?
Also known as code rework. It is when a developer made changes to a specific piece of code including a file, a class, or a function during the development process. Although, it is a normal thing, but also depends on when and why it is taking place.
By this, we mean that testing, reworking, and exploring various solutions to a problem is fine. Especially, during the beginning of the project when code doesn’t have a clear solution.
It is healthy and expected unless it surpasses 20% – This is when it is a problem. The lower the code churn, the closer you get to a release date.
What causes high code churn?
Common workflows and dynamics that can result in high code churn include:
Prototyping is a natural and healthy trend. It is usually seen when there is a new or unfamiliar project. During these times, the churn rate may rise to 60-80% and this is not unusual.
Apart from prototyping, redesign, and POCs are all examples of where large chunks of code are rewritten. Hence, it is fine to allow developers the time and space to research and experiment.
But, if it continues for an extended period beyond what was expected then it is a cause for concern. It could be that the developer is not able to comprehend the specific components or the entire problem. Or the problem could be complex.
Unclear software requirements:
One of the main factors behind high code churn is inconsistent or ambiguous requirements. It further spreads to subsequent phases of software development which compromises the quality of final products.
It could also be that the requirements change midway through the work which is another reason for high code churn. Due to this, developers may rely on their best guess to interpret and fill in any gaps. As a result, some assumptions could be wrong too.
This further damages the morale and progress of the development team.
It may also happen that developers might be juggling between several ways of doing things. It could be because developers might be:
- Figuring out the best way for the task
- Lacking the needed skill
- Struggling to make firm decisions about their project direction
Any of the above leads to subsequent changes in the code base which results in a delay in progress. Since decisions are constantly revisited or revised.
Complex tasks are another reason for more code churns. Since the developers are continuously exploring and backtracking the project, it is not unusual that churn rates may exceed the desired level.
But, as mentioned above, if it goes on for too long, then it is a cause for concern. It could be that developers may not have the resources they need or may require additional help.
It can also increase technical debt resulting in high code churn. As developers are taking shortcuts and making compromises that hinder the entire development process.
Burnout and turnover:
Software developers are more likely to be burnout due to their busy work schedules. Even when enough resources are available and they have the required skills, developers who are burnout may not be able to do their tasks efficiently.
It can further result in becoming disinterested in work, failing to show up, and increasing the rate of presenteeism. Hence, developers may want to change their job resulting in an increased turnover rate.
When former developers resign, new ones replace them. They would be needing time to familiarise themselves with the existing code and team. Hence, it leads to knowledge loss which causes potential errors or inefficient changes.
Why measuring code churn is important?
The only way to manage and minimize code churn is by measuring it. As this allows you to prepare to take things in control when there is an increase in code churn.
Measuring it helps you understand the software development process and know how many times code is changed. It also lets you see in-depth insights into internal and external hurdles allowing you to create actionable plans.
5 metrics to measure code churn are:
Code churn count:
It is the measure of the number of times the developers made changes to the file in GIT control.
The number of lines of code that were added to files for the code that was written recently.
The measure of lines of code that was deleted from files within three weeks of writing the code.
The measure of lines of code that was modified within three weeks of writing the code.
Total code churn:
The total of lines added, lines deleted and lines modified.
How to reduce high code churn?
Define clear project requirements:
High code churn usually arises when requirements are not properly defined. Hence, it is important to take sufficient time to understand the requirements.
In case, the requirements are ambiguous, ask for additional clarification and review it once before starting with the project. Make sure that every team member is on the same page and knows what needs to be done.
Also, aware clients and stakeholders as well of how mid-stream changes can result in slow delivery and increased time.
Address the root cause:
Understanding the root cause lets you identify a long-term solution that helps in improving the quality of the database.
For example, if you are aware that the developers are still lacking needed skills, you can involve pair programming sessions with senior engineers.
Failing to address the root cause makes you constantly make changes to the codebase which lets you create a cycle of rework and inefficiency.
Coding standards and style guides:
Usually, developers spend more time reading code than writing it. Hence, ensure that the code is readable to all.
It could be that developers may have different professional qualifications and work experience. Their language preference and writing styles could be different from each other. Hence, implement standardization in the workplace. And ensure that your team knows about it.
Also, select coding style guides. It will allow developers to read code easier and faster. It further helps in promoting best practices and coding techniques, leading to low code churn.
Code reviews let developers catch errors early in the development process. This further helps in improving code quality.
Apart from this, code reviews also allow developers to identify areas where code can be refactored. As a result, helping them to prevent the need for extensive rework later.
But that’s not all! Code reviews let developers get honest feedback at the right time.
High code churn can signify that developers are innovative and determined. But, when it goes on for a long period, there is a problem that needs to be addressed as soon as possible.