Skip to main navigation Skip to main content Skip to page footer

Automated Source Code Metrics for C and C++

Cantata offers over 300 source code metrics for C/C++, providing an objective and useful measurement and visualization of the non-functional qualities of your source code. These metrics include:

Measuring non-functional qualities involves the static inspection of the source code, which assesses various non-functional features related to the software. This is invoked when building a Cantata-enabled software project. You can configure the analysis through the following methods:

  • Enabling/disabling system headers analysis
  • Specifying which static analysis metrics to calculate using an options file
  • Specifying the source files, functions, or classes to be analyzed
  • Specifying the precise source code statements to be analyzed using pragmas in the source code

By using Cantata, you can improve the quality of your C/C++ code, make it more maintainable, and enhance your development process. Try Cantata today and see how it can help your software project.

Code Complexity and Structure

Cantata offers support for measuring code complexity metrics on procedural source code. These metrics are recognized by academia and are common sense approaches to increase software maintainability through objective measurement. The supported metrics include:

  • Halstead’s Software Science metrics
  • McCabe’s, Myers’, and Hansen’s cyclomatic complexity metrics
  • Average and maximum nesting level
  • Basic counts of language constructs such as comments, lines of code, statements, and parameters.

By incorporating these metrics into the development process, Cantata can help developers identify potential problem areas in the codebase and make improvements to increase software quality and maintainability.

Object-Oriented Implementation

Cantata offers more than just code complexity measures for object-oriented code. It also provides a comprehensive set of source code metrics that measure different aspects of object-oriented implementation. These metrics include:

  • Chidamber and Kemerer’s MOOSE metric set.
  • Fernando Brito e Abreu’s MOOD metric set.
  • Bansiya and Davis’ QMOOD metric set.
  • Robert Martin’s object-oriented dependency metrics.
  • McCabe’s object-oriented metrics.
  • Bansiya’s class entropy metrics.

We understand the importance of accurate and actionable source code metrics. That’s why all our metrics are provided at the function, class, translation unit, or system level, as appropriate. With Cantata’s source code metrics, you can gain insights into the quality and maintainability of your codebase and make data-driven decisions to improve your software development process.

Testing Effort Estimation

Understanding the complexity of source code is essential for estimating the time required for testing. Cantata’s source code metrics utilize industry-standard complexity measures to provide accurate estimations of testing efforts for source items. For example, McCabe Cyclomatic Complexity and its variants can be used to determine the minimum number of test cases needed to achieve complete decision code coverage.

Visualising and Reporting Metrics

Visualizing data through graphs can enhance understanding and provide an overall view of trends that may not be immediately apparent from numerical metrics alone. Graphs can be plotted at various levels, including class, function, or category. While formatted metrics are valuable, graphical representation can be even more useful for data analysis.

Example Uses of Metrics

As Cantata can produce over 300 static metrics on source code, below are some examples of specific metrics and their most useful application. For an exhaustive list please refer to the Cantata manual.

Standard Code Size Metrics

These are simple metrics regarding the number of lines of code, comments, etc.

Standard Code Quality Metrics

The quality of a piece of software is to some degree based on the number of occurrences of dubious code contained within it. These metrics alert the user of such occurrences.

Standard Complexity Metrics

The complexity of a piece of code is generally regarded as a measure that will affect the effort involved with maintaining it. These metrics attempt to estimate the complexity of the software based on various factors, such as the level of nesting.

Specialist Object Oriented Metrics

Many standard metrics are still applicable to OO systems. For example, the maximum nesting levels within functions is also applicable to class methods. However there are also a range of specific OO metrics. These may be with respect to a given class, or for the system as a whole.

The ‘OO’ aspects of the C++ language have tended to render the old procedural C metrics less useful, but fortunately new sets of metrics have taken their place. The popular ones include MOOSE (Metrics for OO Software Engineering), MOOD (Metrics for OO Design), and QMOOD (Quality Metrics for OO Design). Between them they define a number of metrics which can be useful for judging whether a C++ class is ‘worth testing’. Some examples are:

Additional System Metrics

Additional system level metrics can be created by taking averages for various class or function scope metrics. For example, we can calculate the mean McCabe Cyclomatic Complexity value for all functions or methods within our system.