scitools.com

← Metric catalog

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

API IDCountDeclClassNew
TargetsArchitectures Files Project
LanguagesBasic C# C++ Java Pascal Python Web
CategoriesCompare Contents
CostCached

Number of new classes, compared to the comparison database.

Counts classes defined in the current database but not in the comparison database. See Classes for what counts as a class. Since changes come from a textual diff, a class 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 classes as new or removed.

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

--- classes.cpp (comparison database)
+++ classes.cpp (current)
@@ -1,32 +1,47 @@
 #define TAG_CLASS(Name) \
   class Name {          \
   public:               \
     int tag = 0;        \
   };
 
 TAG_CLASS(Marker)
+TAG_CLASS(Flag)
+
+struct Size {
+  int width;
+  int height;
+};
 
 struct Point {
   int x;
   int y;
-};
-
-union Value {
-  int asInt;
-  float asFloat;
+  int z;
 };
 
 class Shape {
 public:
   virtual double area() const = 0;
 };
 
 class Circle : public Shape {
 public:
   double area() const override;
   double r = 1;
 };
 
 double Circle::area() const {
-  return 3.14 * r * r;
+  return 3.14159 * r * r;
 }
+
+class Square : public Shape {
+public:
+  double area() const override { return side * side; }
+  double side = 1;
+};
+
+union Number {
+  int asInt;
+  double asDouble;
+};
+
+enum class Color { Red, Green };

The class Square, the struct Size, and the union Number are new, so CountDeclClassNew = 3. Flag is new too, but the TAG_CLASS macro defines it. With the strict C/C++ parser, a class defined by a macro has no lines of its own, so it doesn't count. The fuzzy parser gives it the line where the macro is used. The scoped enum Color isn't a class.

See Removed Classes for the reverse of this metric, Changed Classes for classes in both versions that differ, and Classes 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 class changed.