scitools.com

← Metric catalog

Changed Program Units is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Changed Program Units

API IDCountDeclProgUnitChanged
TargetsArchitectures Files Project
LanguagesFortran
CategoriesCompare Contents
CostCached

Number of changed program units, compared to the comparison database.

Counts program units defined in both databases whose text differs. A program unit counts once, however many of its lines changed. See Program Units for what counts as a program unit. Since changes come from a textual diff, a program unit must have Lines to count. For an architecture or the project, the counts from its files are added together. A file added to or removed from an architecture counts all of its program units as new or removed.

For example, diffing a file's current version against the comparison database's version:

--- progunits.f90 (comparison database)
+++ progunits.f90 (current)
@@ -1,29 +1,46 @@
 MODULE shapes
   IMPLICIT NONE
 CONTAINS
   REAL FUNCTION circle_area(r)
     REAL, INTENT(IN) :: r
-    circle_area = 3.14 * r * r
+    circle_area = 3.14159 * r * r
   END FUNCTION circle_area
+
+  REAL FUNCTION square_area(side)
+    REAL, INTENT(IN) :: side
+    square_area = side * side
+  END FUNCTION square_area
 END MODULE shapes
 
 SUBROUTINE log_value(x)
   REAL, INTENT(IN) :: x
   PRINT *, x
 END SUBROUTINE log_value
 
-SUBROUTINE old_report(x)
-  REAL, INTENT(IN) :: x
-  PRINT *, 'value:', x
-END SUBROUTINE old_report
-
 REAL FUNCTION double_it(x)
   REAL, INTENT(IN) :: x
   double_it = 2 * x
 END FUNCTION double_it
 
+REAL FUNCTION triple_it(x)
+  REAL, INTENT(IN) :: x
+  triple_it = 3 * x
+END FUNCTION triple_it
+
+SUBROUTINE new_report(x)
+  REAL, INTENT(IN) :: x
+  PRINT *, 'new value:', x
+END SUBROUTINE new_report
+
+BLOCK DATA init_data
+  LOGICAL :: verbose
+  COMMON /settings/ verbose
+  DATA verbose /.FALSE./
+END BLOCK DATA init_data
+
 PROGRAM main
   USE shapes
   IMPLICIT NONE
   CALL log_value(circle_area(1.0))
+  CALL new_report(square_area(2.0))
 END PROGRAM main

The module shapes has a changed function and a new one nested inside it, and the main program main has a new line, so CountDeclProgUnitChanged = 2. The nested circle_area changed too, but it isn't a program unit, so it only counts as part of shapes. log_value and double_it are the same in both versions, so neither counts.

See New Program Units and Removed Program Units for program units that exist in only one version, and Program Units for the total count. See Compare two versions of a project ↗ for how entities are compared, and New Lines, Removed Lines, and Changed Lines for how much a program unit changed.