scitools.com

← Metric catalog

New 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.

New Lines

API IDCountLineNew
TargetsArchitectures Classes Files Functions Modules Packages Project Subprograms
LanguagesAda Assembly Basic C# C++ Fortran Java Jovial Pascal Python Rust VHDL Web
SolutionHersteller Initiative Software (HIS)
CategoriesCompare Lines
CostCached

Number of new 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 added is greater than lines deleted, then added - deleted is added to the new line count. So, insertions (deleted=0) are new lines, and also added lines in a changed region that exceed the number of lines deleted.

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 added std::cout << cube(3) << std::endl; is a new line from a simple insertion (no removed lines). There's also a new line from the cube function because the new region is 3 lines while the old region was only 2, so the difference counts as a new line. That gives CountLineNew = 2.

See Changed Lines for the lines a region has in common, Removed Lines for the reverse of this metric, and Percent Changed for a single score combining all three.