Code Quality - CL3 Flashcards
Metrics: Chidamber and Kemmerer Object-Oriented metrics
The Chidamber & Kemerer metrics suite originally consists of 6 metrics calculated for each class: WMC, DIT, NOC, CBO, RFC and LCOM1. The original suite has later been amended by RFC´, LCOM2, LCOM3 and LCOM4 by other authors.
WMC Weighted Methods Per Class
Despite its long name, WMC is simply the method count for a class.
Keep WMC down. A high WMC has been found to lead to more faults.
DIT Depth of Inheritance Tree
A recommended DIT is 5 or less.
NOC Number of Children
High NOC has been found to indicate fewer faults. This may be due to high reuse, which is desirable.
CBO Coupling between Object Classes High CBO is undesirable. Excessive coupling between object classes is detrimental to modular design and prevents reuse. The more independent a class is, the easier it is to reuse it in another application.
RFC and RFC´ Response for a Class
A large RFC has been found to indicate more faults.
LCOM1 Lack of Cohesion of Methods
The figures suggest that the higher the CBO and WMC, the lower the quality of the system.
Link:
https://www.aivosto.com/project/help/pm-oo-ck.html
Metrics: OOD Metrics (Distance, Abstractness)
EFFERENT COUPLING (CE) This metric is used to measure interrelationships between classes. As defined, it is a number of classes in a given package, which depends on the classes in other packages. It enables us to measure the vulnerability of the package to changes in packages on which it depends.
AFFERENT COUPLING (CA) This metric is an addition to metric Ce and is used to measure another type of dependencies between packages, i.e. incoming dependencies. It enables us to measure the sensitivity of remaining packages to changes in the analysed package.
INSTABILITY (I) This metric is used to measure the relative susceptibility of class to changes. According to the definition instability is the ration of outgoing dependencies to all package dependencies and it accepts value from 0 to 1.
ABSTRACTNESS (A)
This metric is used to measure the degree of abstraction of the package and is somewhat similar to the instability. Regarding the definition, abstractness is the number of abstract classes in the package to the number of all classes.
NORMALIZED DISTANCE FROM MAIN SEQUENCE (D)
This metric is used to measure the balance between stability and abstractness
Link:
https://linux.ime.usp.br/~joaomm/mac499/arquivos/referencias/oodmetrics.pdf
Software Metrics by levels: Project, File, Function, Class, Method
Project Level Number of Interfaces (INTERFS) Number of Abstract Classes (CLSa) Number of Concrete Classes (CLSc) Number of Classes (CLS) Number of Root Classes (ROOTS) Number of Leaf Classes (LEAFS) Maximum Depth of Intheritance Tree (maxDIT)
File Level Lines of Code (LOC) Comment Lines of Code (CLOC) Non-Comment Lines of Code (NCLOC) Lines of Executable Code (ELOC) Lines of Executed Code Code Coverage
Function Level Lines of Code (LOC) Lines of Executable Code (ELOC) Lines of Executed Code Code Coverage Cyclomatic Complexity Change Risk Analysis and Predictions (CRAP) Index
Class Level Lines of Code (LOC) Lines of Executable Code (ELOC) Lines of Executed Code Code Coverage Attribute Inheritance Factor (AIF) Attribute Hiding Factor (AHF) Class Size (CSZ) Class Interface Size (CIS) Depth of Inheritance Tree (DIT) Method Inheritance Factor (MIF) Method Hiding Factor (MHF) Number of Children (NOC) Number of Interfaces Implemented (IMPL) Number of Variables (VARS) Number of Non-Private Variables (VARSnp) Number of Variables (VARSi) Polymorphism Factor (PF) Weighted Methods per Class (WMC) Weighted Non-Private Methods per Class (WMCnp) Weighted Inherited Methods per Class (WMCi)
Method Level Lines of Code (LOC) Lines of Executable Code (ELOC) Lines of Executed Code Code Coverage Cyclomatic Complexity Change Risk Analysis and Predictions (CRAP) Index
Link:
https://web.archive.org/web/20090126071522/http://sebastian-bergmann.de/archives/689-PHPUnit-and-Software-Metrics.html
Cyclomatic complexity metric
Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program’s source code. It was developed by Thomas J. McCabe, Sr. in 1976.
Cyclomatic complexity is computed using the control flow graph of the program: the nodes of the graph correspond to indivisible groups of commands of a program, and a directed edge connects two nodes if the second command might be executed immediately after the first command. Cyclomatic complexity may also be applied to individual functions, modules, methods or classes within a program.
One testing strategy, called basis path testing by McCabe who first proposed it, is to test each linearly independent path through the program; in this case, the number of test cases will equal the cyclomatic complexity of the program.
Link:
https://en.wikipedia.org/wiki/Cyclomatic_complexity
Maintainability Index
Maintainability Index – Calculates an index value between 0 and 100 that represents the relative ease of maintaining the code. A high value means better maintainability. Color coded ratings can be used to quickly identify trouble spots in your code. A green rating is between 20 and 100 and indicates that the code has good maintainability. A yellow rating is between 10 and 19 and indicates that the code is moderately maintainable. A red rating is a rating between 0 and 9 and indicates low maintainability.
Link:
https://docs.microsoft.com/ru-ru/visualstudio/code-quality/code-metrics-values?view=vs-2015&redirectedfrom=MSDN
Heavyweight software audits and inspections, Fagan inspections
Inspection in software engineering, refers to peer review of any work product by trained individuals who look for defects using a well defined process. An inspection might also be referred to as a Fagan inspection after Michael Fagan, the creator of a very popular software inspection process.
Links:
https: //en.wikipedia.org/wiki/Software_inspection
https: //en.wikipedia.org/wiki/Fagan_inspection