Cantata provides over 300 source code metrics on C/C++ which provides useful objective measurement and visualisation of non-functional qualities of the source code:
Measurement of non-functional qualities involves the static inspection of the source code in order to provide an assessment of various non-functional features relating to the software, and is invoked on a build of a Cantata enabled software project. Configuring the analysis can be achieved through the following methods:
Code quality and complexity metrics provided by Cantata can help users to determine areas of the code that will most likely suffer from bugs, as well as producing data from which the time required for testing can be estimated. Once the metrics have been gathered by Cantata they can be processed and manipulated using an add-in for Microsoft Excel.
Cantata supports code complexity metrics on procedural source code as a means of increasing the maintainability of software, through objective measurement using recognised ‘academic’ and common sense metrics:
In addition to code complexity measures for object oriented code, Cantata also provides a number of metrics which measure aspects of object oriented implementation. These include:
All metrics are provided at the function, class, translation unit, or system level, as appropriate.
Organisations are increasingly adopting coding standards as a means of improving software quality and maintainability. However, unless these standards can be verified in an automated way, it is difficult to enforce them effectively. While Cantata is not a coding standards rule checking product, it does provide the developer with static analysis metrics on the use of several useful coding constructs such as:
Understanding how complex the source code is, can be very helpful for estimating how long it will take to test it. Cantata source code metrics use industry standard complexity metrics to accurately estimate the testing effort for source items. An example is McCabe Cyclomatic Complexity and its variants, the result of which equals the minimum number of test cases required to achieve 100% decision code coverage.
Although the formatted metrics are very useful it is often more helpful to visualise the data graphically. Plotting graphs of the data can aid understanding and create overall pictures of the trends occurring lower down that are not immediately obvious when you are reading the metrics as numbers alone. Metrics visualisation can be plotted at the class, function or category level.
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.
These are simple metrics regarding the number of lines of code, comments, etc.
|LINE_CODE||Total number of lines of code (including blank lines and comments).||Function or system|
|LINE_COMMENT||Total number of lines of comments (both C and C++).||Function or system|
|LINE_SOURCE||Total number of lines of source code (not including blank lines or comments).||Function or system|
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.
|LABEL_GOTOUSED||Number of goto labels that are used.||Function or system|
|LABEL_GOTOUNUSED||Number of unused goto labels.||Function or system|
|STMT_GOTO||Number of goto statements.||Function or system|
|SWITCH_NODEF||Number of switch statements with no default.||Function or system|
|SWITCH_FALLTHRU||Number of non-empty case blocks which fall through to the next case block.||Function or system|
|UNREACHABLE||Number of statically unreachable statements in the given scope.||Function or system|
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.
|HALSTEAD_PARAMS||Number of parameters.||Function|
|MCCABE||The McCabe Cyclomatic Complexity value for the function.||Function|
|NESTING_MAX||Maximum statement nesting level.||Function|
|NESTING_SUM||Sum of the statement nesting levels for all statements in the function.||Function|
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.
|MAX_DEPTH||Maximum length of inheritance path to ultimate base class.||System|
|MOOD_AD||Number of new attributes defined for this class.||Class|
|MOOD_MD||Number of new methods plus overridden methods defined for this class.||Class|
|MOOD_AHF||Proportion of attributes that are hidden (private or protected).||Class|
|MOOD_MHF||Proportion of methods that are hidden (private or protected).||Class|
|MOOSE_CBO||Level of coupling between objects. The number of classes with which this class is coupled (via a non-inheritance dependency from this class to that, or vice versa).||System|
|MOOSE_WMC_MCCABE||Average McCabe Cyclomatic Complexity value of for all methods of the class (excluding inherited methods) defined in this translation unit.||Class|
|MOOSE_LCOM98||Chidamber & Kemerer’s Lack of Cohesion of Methods metric (1998 definition). The minimum number of disjoint clusters of (new or overridden) methods (excluding constructors), where each cluster operates on disjoint set of (new) instance variables.||Class|
|MOOSE_RFC||Chidamber & Kemerer’s Response for a class metric. The number of methods or functions defined in the class or called by methods of the class.||Class|
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:
|Quality identified in source code||EXAMPLE METRICS|
|Poor or Questionable Design|| |
‘MOOSE Lack of Cohesion among Methods’
‘MOOD Attribute Hiding Factor’
|Estimated Number of Faults|| |
‘MOOD Methods Defined’
‘MOOD Attributes Defined’
‘MOOSE Weighted Methods in Class’
|General Complexity|| |
‘MOOSE Depth of Inheritance’
‘QMOOD Number of Ancestors’
‘MOOSE Number of Children’
|Estimated Test Effort|| |
‘MOOSE Response for a Class’
‘MOOSE Coupling Between Objects’
‘MOOD Method Hiding Factor’
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.