Removed Lines 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.
Removed Lines
| API ID | CountLineRemoved |
| Targets | Architectures Classes Files Functions Modules Packages Project Subprograms |
| Languages | Ada Assembly Basic C# C++ Fortran Java Jovial Pascal Python Rust VHDL Web |
| Solution | Hersteller Initiative Software (HIS) |
| Categories | Compare Lines |
| Cost | Cached |
Number of removed lines, compared to the comparison database.
Understand does a textual diff of the entity's contents and processes each
changed region, meaning a run of adjacent added and deleted lines bounded by
unchanged lines. For each changed region, if lines deleted is greater than lines added, then deleted - added is added to the removed line count. So, deletions (added=0) are removed lines, and also deleted lines in a changed region that exceed the number of lines added.
Note that because this is specific to the entity's contents, things like reordering every function in a file while leaving function contents unchanged means that each individual function will be unchanged, even though the file changed. Also, an entity's lines are counted the same way they are for the Lines metric, so a C++ Class considers all the defined method bodies even when the definition is outside the class definition.
For an architecture, the value is the sum over its entities, including those in child architectures. An entity in more than one child architecture counts once for each. An entity added to or removed from the architecture counts all of its lines as new or removed, even if the entity itself didn't change.
For example, diffing a file's current version against the comparison database's version:
--- sample.cpp (comparison database)
+++ sample.cpp (current)
@@ -1,15 +1,16 @@
#include <iostream>
-// Utility functions
int square(int x) {
- return x * x;
+ return x * x * x;
}
-int unused() {
- return 0;
+// Compute a cube
+int cube(int x) {
+ return x * x * x;
}
int main() {
std::cout << square(4) << std::endl;
+ std::cout << cube(3) << std::endl;
return 0;
}
The // Utility functions comment is a removed line from a simple deletion (no added lines). All other changed regions have at least as many lines added as there were lines deleted, so CountLineRemoved = 1.
See Changed Lines for the lines a region has in common, New Lines for the reverse of this metric, and Percent Changed for a single score combining all three.