Code Churn

Code churn is a measure that tells you the rate at which your code evolves. Code churn has several usages:

  • Visualize your development process: Your code churn signature in the diagrams below mirrors the practices you use to deliver code. You may want to watch out for regular spikes, which may hint at a mini waterfall going on in your daily work

  • Reason about delivery risks: Code churn is a good predictor of post-release defects. Thus, it’s a warning sign if you approach a deadline while your code churn increases. That’s a sign that the code gets more and more volatile the closer you get to your deadline. You want the opposite. You want to stabilize more and more code the closer you get to delivery.

  • Track trends by task: CodeScene lets you inspect the size and impact of your tasks. Use the information to see if your project management tasks are on an appropriate level or if each one of them implies a mini big bang in terms of code changes.

CodeScene provides several churn measures. They’re all described in this guide and you typically investigate all of them to get the overall trend in your codebase.

Use the Commit Activity as the Pulse of your Codebase

The commit activity chart shows the number of commits and contributing authors over time as illustrated in Fig. 154.

Commit and Author activity

Fig. 154 The commit activity chart.

The number of commits and authors over time is a different kind of churn. This metric will typically correlate well with your other Code Churn metrics described below. However, you want to look out for potential productivity issues like an increase in authors without a corresponding increase in commits and churn; Such a trend often indicates that you’ve more programmers contributing than the software architecture (and/or organization) can support.

Inspect The Level of your Tasks

It’s a challenge to strike the right level when you partition your work into individual tasks. Large tasks are hard to reason about and also less predictable to plan. That’s why we generally prefer small and well-focused tasks.

CodeScene lets you inspect the impact of your project management tasks on the codebase in terms of both code churn and collaboration (that is, how many authors worked together to solve the task?) as illustrated in Fig. 157.

Code Churn by Ticket ID

Fig. 157 Inspect the code churn on a task level.

CodeScene uses your Ticket ID to group individual commits into tasks. As you see in Fig. 157, CodeScene also calculates a Lead Time for each task. The lead time is the time that passed between the first and the last commit referencing a specific task. Note that many tasks tend to be solved in a single commit. In that case CodeScene doesn’t have the data to calculate a proper lead time. So CodeScene defaults to one hour in case of a task that’s resolved in a single commit.

We recommend that you use the lead time data to track tasks that drift in time. Often, those tasks suggests requirements that aren’t as well-defined as they could be. You can also use the lead time analysis to track the effects of process changes in your organization.