Changed Subprograms 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 Subprograms
| API ID | CountDeclSubprogramChanged |
| Targets | Architectures Files Functions Modules Packages Project Subprograms |
| Languages | Ada Basic Fortran Jovial Pascal |
| Categories | Compare Contents |
| Cost | Cached |
Number of changed subprograms, compared to the comparison database.
Counts subprograms defined in both databases whose text differs. A subprogram counts once, however many of its lines changed. See Subprograms for what counts as a subprogram. Since changes come from a textual diff, a subprogram 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 subprograms as new or removed.
For example, diffing a file's current version against the comparison database's version:
--- subprograms.adb (comparison database)
+++ subprograms.adb (current)
@@ -1,25 +1,34 @@
with Ada.Text_IO;
package body Subprograms is
function Circle_Area (R : Float) return Float is
begin
- return 3.14 * R * R;
+ return 3.14159 * R * R;
end Circle_Area;
function Square_Area (S : Float) return Float is
begin
return S * S;
end Square_Area;
- procedure Old_Report (X : Float) is
- begin
- Ada.Text_IO.Put_Line ("Value:" & Float'Image (X));
- end Old_Report;
-
procedure Log_Value (X : Float) is
begin
- Ada.Text_IO.Put_Line (Float'Image (X));
+ Ada.Text_IO.Put_Line ("Logged:" & Float'Image (X));
end Log_Value;
+ function Triangle_Area (B, H : Float) return Float is
+ begin
+ return B * H / 2.0;
+ end Triangle_Area;
+
+ procedure New_Report (X : Float) is
+ function Format (V : Float) return String is
+ begin
+ return "Report:" & Float'Image (V);
+ end Format;
+ begin
+ Ada.Text_IO.Put_Line (Format (X));
+ end New_Report;
+
end Subprograms;
Circle_Area and Log_Value have changed lines, so CountDeclSubprogramChanged = 2. Square_Area is the same in both versions, so it doesn't count.
In Ada, a subprogram declared in a spec file and defined in a body file counts once, in the body file. Its declaration in subprograms.ads doesn't add to these counts, even though Subprograms counts it in both files.
See New Subprograms and Removed Subprograms for subprograms that exist in only one version, and Subprograms 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 subprogram changed.