New Executable 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.
New Executable Units
| API ID | CountDeclExecutableUnitNew |
| Targets | Architectures Files Project |
| Languages | Ada Basic C# Fortran Java Pascal Python Web |
| Categories | Compare Contents |
| Cost | Cached |
Number of new executable units, compared to the comparison database.
Counts executable units defined in the current database but not in the comparison database. See Executable Units for what counts as an executable unit. Since changes come from a textual diff, an executable 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 executable units as new or removed.
For example, diffing a file's current version against the comparison database's version:
--- executableunits.java (comparison database)
+++ executableunits.java (current)
@@ -1,23 +1,41 @@
abstract class Shape {
abstract double area();
+ abstract double scale(double factor);
+
String describe() {
- return "shape";
+ return "a shape with area " + area();
}
}
class Circle extends Shape {
double r = 1;
- double perimeter() {
- return 2 * 3.14 * r;
- }
-
String name() {
return "circle";
}
+ Circle(double r) {
+ this.r = r;
+ }
+
double area() {
- return 3.14 * r * r;
+ return 3.14159 * r * r;
+ }
+
+ double scale(double factor) {
+ return area() * factor * factor;
}
}
+
+class Square extends Shape {
+ double side = 1;
+
+ double area() {
+ return side * side;
+ }
+
+ double scale(double factor) {
+ return area() * factor * factor;
+ }
+}
The constructor Circle(double), Circle.scale(), Square.area(), and Square.scale() are new, so CountDeclExecutableUnitNew = 4. Shape.scale() is new too, but it's abstract, so it has no implementation and doesn't count.
In Web, a file with top-level code also counts as an executable unit. It's new or removed when that code appears or disappears, and otherwise it has the status of the whole file, so any change to the file counts it as changed.
See Removed Executable Units for the reverse of this metric, Changed Executable Units for executable units in both versions that differ, and Executable 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 an executable unit changed.