Docs
Code Churn

Code Churn metrics

What is code churn?

Code churn, also known as code rework, is when a developer deletes or rewrites their code shortly after it has been composed.

Code churn is a normal part of software development and identifying code churn can help managers notice when a deadline is at risk, when an engineer is stuck or struggling, problematic code areas, or when issues concerning external stakeholders come up.

It is common for newly composed code to go through multiple changes. The volume and frequency of code changes in a given period of time can vary due to several factors and code churn can be good or bad depending upon when and why it is taking place.

For example, engineers frequently test, rewrite, and examine several solutions to an issue particularly at the beginning of a new project or task when they are experimenting with solutions to the task at hand. In this case, code churn is good, because it is a result of creative problem-solving.

Note that Code churn could also be influenced by how the delivery of a feature is planned and how the code is modularised. For instance a function shim could be shipped in 1 release, followed by some functionality in the next release, followed by error handling in the next. This would show up as high code churn. Keep this context while looking at Code Churn metrics, low is not always good, high is not always bad.

Code churn breakdown

There are 4 components to code churn:

  1. Code churn - as detailed above
  2. Refactor Code that is modified after 21 days of committing is called refactored code. Refactored code is usually an acceptable change that is needed for maintenance hence, is distinct from code churn so as not to raise any red flags.
  3. New work: Code that is newly added and that is not replacing or rewriting existing code.
  4. Help others: Code that is replaced by engineers other than the author of the original code within 21 days of authoring. This helps you measure to what extent developers are helping their teammates to improve code quality and delivery.

Connectors used

VCS tools → Github, Gitlab and Bitbucket

Additional resources

  1. Code churn 101
  2. Causes of code churn