28.4. CodeChurn

28.4.1. Description

CodeChurn reduction function computes a single telemetry stream representing churn in the project. It can be either the number of lines added and/or the number of lines deleted from files in the Project as they are committed to the configuration management repository.

28.4.2. Parameter

Table 28.3. 

ParameterDescriptionDefault
modeOne of 'LinesAdded' or 'LinesDeleted'LinesAdded
filePatternAnt-like file pattern specifying the files to be included in computation.**
isCumulativeIf true, an cumulative version of telemetry stream is returned.false

28.4.3. Example 1

Example 28.4. Net Churn

streams NetCodeChurnStream(filePattern, cumulative) = {
   "Added minus Deleted",
   CodeChurn("LinesAdded", filePattern, cumulative) -
   CodeChurn("LinesDeleted", filePattern, cumulative)
};

y-axis yAxis(label) = {label};

chart NetCodeChurnChart(filePattern, cumulative) = {
  "Lines Added minus Lines Deleted", 
  (NetCodeChurnStream(filePattern, cumulative), yAxis("Lines Added - Lines Deleted Count"))
};

draw NetCodeChurnChart("**/*.java", "false");

This chart shows the net churn, which is defined as 'LinesAdded' - 'LinesDeleted'. Net churn is good for factoring out the effects of refactoring, where a large number of lines of code might be deleted from one file and added to another.

28.4.4. Example 2

Example 28.5. Churn: Lines Added and Lines Deleted

streams LinesAddedStream(filePattern, cumulative) = {
   "Lines Added",
   CodeChurn("LinesAdded", filePattern, cumulative)
};

streams LinesDeletedStream(filePattern, cumulative) = {
   "Lines Deleted",
   CodeChurn("LinesDeleted", filePattern, cumulative)
};

y-axis yAxis(label) = {label};

chart CodeChurnChart(filePattern, cumulative) = {
  "Lines Added and Lines Deleted", 
  (LinesAddedStream(filePattern, cumulative), yAxis("Lines Count")),
  (LinesDeletedStream(filePattern, cumulative), yAxis("Lines Count"))
};

draw CodeChurnChart("**/*.java", "false");

The chart shows both lines added and lines deleted.