Definition of Code metrics
In English, metrics refer to statistics and measurements. Thus, code metrics are all the data that say something about the software (source code) that your team or organization produces. You use these data to assess the quality, complexity and maintainability of your code.Examples
- Cyclomatic Complexity – This measures the complexity of the code by counting the number of decision points in a code fragment. Higher complexity may indicate code that is difficult to understand and could perhaps be better rewritten (refactoring).
- Lines of Code – This measures the size of the codebase in terms of the number of written lines. While it gives a picture of the overall size, it says nothing about the quality or efficiency of the code.
- Code Coverage – Code Coverage is the percentage of code that is covered by tests, indicating the extent to which the code has been tested by the test suite.
- Technical Debt – This quantifies the work needed to fix issues, such as inefficient code or shortcuts in the code (hacks) that might arise, for example, from development cycles under too much pressure.
- Duplication – Identifying duplicated code helps you improve the maintainability of the software by subsequently rewriting parts of the code (refactoring).
- Maintainability Index – This evaluates how maintainable the code is by considering factors such as complexity, size, duplication and clarity of the code.