Code Churn is when an engineer rewrites or deletes their own code that is less than 3 weeks old. When determining code Churn, we look to the lines of code that are removed or changed, but we also look for a set of context lines to determine if multiple changes are within the same hunk of code or a separate hunk of code. The set of context lines is determined by the default “git dif” which is a block of 4 or more lines of unchanged code before and/or after changes. Before moving forward here are a few definitions to keep in mind:
- Hunk - A hunk is a continuous block of change. A hunk can include removed, added or unchanged lines of code.
- Block - A block of code is delineated by 4 or more lines of unchanged code. Also referred to as “context lines”.
Let’s look at a few specific examples to see how churn is calculated:
1. All Churn no New Work
In the example below, although we are seeing new lines of code being added (lines 100-104 and 106-119) since there are only three lines of context (a block of unchanged lines of code) between the new code added and the deleted line on line 100, all this code will be reported as one hunk, and therefore all Churn.
2. Some Churn and some New Work
In the following example we are seeing four lines of context (a block of unchanged lines of code) between the first line of code deletion (line 68) and the second set of code removals (lines 77-79). Therefore, lines 72-72 will be considered New Work.
As long as there are 4 lines or more of unchanged lines of code between each of your code changes then each will be marked as a separate hunk and calculated as such. If you want more information about Churn, check out What is Churn and our blog post 6 Causes of code Churn and what you should do about them.
If you need help, please email firstname.lastname@example.org for 24/7 assistance.