2. Outline: Metrics on application
• Lines of Code (LOC)
• Lines of Comments
• Percentage Comment
• Number of IL Instructions
• Number of Assemblies
• Number of Namespaces
• Number of Types Number of Methods
• Number of Fields
• Number of Parameters
• Number of Variables
• Efferent coupling (Ce)
• Afferent coupling (Ca)
• Instability (I)
• Abstractness
• Cohesion metrics
• Relational Cohesion (H)
• Depth of inheritance tree (DIT)
• Number of children (NOC)
• Association between classes (ABC)
• Cyclomatic complexity (CC)
Presented By : Moutasm Tamimi , 2018
3. Software metric
A software metric is a standard of measure
of a degree to which a software system or
process possesses some property.
Presented By : Moutasm Tamimi , 2018
4. Lines of Code (LOC)
Metrics type description Example
Lines of Code (LOC) Physical Line of Code (LOC)=4
Logical Lines of Code (LLOC)=2
for (i = 0; i < 100; i++)
{
printf("hello");
}
Recommendations
1. Methods where NbLinesOfCode is higher than 20 are hard to understand and maintain
2. Methods where NbLinesOfCode is higher than 40 are extremely complex and should be split in
smaller methods
Presented By : Moutasm Tamimi , 2018
5. Lines of Comments
Metrics type Description Example
Lines of Comments a comment is a programmer-readable
explanation or annotation in the source code
of a computer program. They are added with
the purpose of making the source code easier
for humans to understand, and are generally
ignored by compilers and interpreters.
/* welcome to the system
…..
*/
Percentage Comment 100 * NbLinesOfComment / (
NbLinesOfComment + NbLinesOfCode)
NbLinesOfComment =10
NbLinesOfCode=50
Percentage Comment =
100*10/(10+50)= 16.6
Recommendations
This metric is not helpful to assess the quality of source code
Presented By : Moutasm Tamimi , 2018
6. Number of Intermediate language Instructions
Metrics type Description Example
Nb IL Instructions Intermediate language. Code exists on
many levels. Abstraction is a ladder. At the
highest levels of abstraction, we have C#
code. At a lower level, we have an
intermediate language.
Instructions. The IL has instructions
(opcodes - operation code) that manipulate
the stack. These instructions, called
intermediate language opcodes, reside in a
relational database called the metadata
Recommendations
NbILInstructions is higher than 100 are hard to understand and maintain.
Methods where NbILInstructions is higher than 200 are extremely complex and should be split in smaller methods
Presented By : Moutasm Tamimi , 2018
7. Assemblies, Namespace, Type, Method, Field
Metrics type Description Example
NbAssemblies Defined for application
An assembly provides a fundamental unit of physical code
grouping.
(Security, Type Identity
Reference Scope, Versioning
Deployment)
System.Windows.Forms.dll
assembly
NbNamespaces Defined for application, assemblies
A namespace provides a fundamental unit of logical code
grouping.
class library packages
NbTypes An abstract or a concrete class, a structure, an enumeration, a
delegate class or an interface.
Classes
NbMethods A method can be an abstract, virtual or non-virtual method, a
method declared in an interface, a constructor, a class
constructor, a finalizer, a property/indexer getter or setter, an
event adder or remover
Methods
Recommendations
NbMethods > 20 might be hard to understand and maintain but there might be cases where it is relevant to have a high value
for NbMethods
NbFields field can be a regular field, an enumeration's value or a read-
only or a const field
Int x;
10. Outline: Metrics on application
• Lines of Code (LOC)
• Lines of Comments
• Percentage Comment
• Number of IL Instructions
• Number of Assemblies
• Number of Namespaces
• Number of Types Number of Methods
• Number of Fields
• Number of Parameters
• Number of Variables
• Efferent coupling (Ce)
• Afferent coupling (Ca)
• Instability (I)
• Abstractness
• Cohesion metrics
• Relational Cohesion (H)
• Depth of inheritance tree (DIT)
• Number of children (NOC)
• Association between classes (ABC)
• Cyclomatic complexity (CC)
Presented By : Moutasm Tamimi , 2018
11. Coupling
• The degree of interdependence between software modules; a
measure of how closely connected two routines or modules are; the
strength of the relationships between modules.
Presented By : Moutasm Tamimi , 2018
12. Coupling
• Tight coupling (high coupling) A module has many relations with
many other modules, less maintainability
• Loose coupling (low coupling) A module has fewer relationships with
other modules.
low coupling is better situation
• maintainability – changes are confined in a single module
• testability – modules involved in unit testing can be limited to a minimum
• readability – classes that need to be analyzed are kept at a minimum
• Understand one class without reading others
• Change one class without affecting others
Presented By : Moutasm Tamimi , 2018
13. Efferent coupling (Ce)
Efferent coupling (Ce) of types within this package
that depend on types outside this package.
Ex It measures the number of data types
Ex Outgoing Dependencies or the Number of Types
inside a Package that Depend on Types of other
Packages
A large efferent coupling can indicate that a
package is unfocussed and may also indicate that it
is unstable since it depends on the stability of all
the types to which it is coupled
Presented By : Moutasm Tamimi , 2018
14. Afferent coupling (Ca)
• Number of types outside this package that depend on types within
this package.
Presented By : Moutasm Tamimi , 2018
15. 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.
• I=0 indicates a completely stable package, painful to modify.
• I=1 indicates a completely instable package.
Presented By : Moutasm Tamimi , 2018
16. Abstractness
• Abstractness (A): ratio of the number of internal abstract types to the
number of internal types.
• A=0 indicates a completely concrete package.
• A=1 indicates a completely abstract package
Presented By : Moutasm Tamimi , 2018
17. Cohesion metrics
• Cohesion metrics measure how well the methods of a class are related to
each other. A cohesive class performs one function. A non-cohesive class
performs two or more unrelated functions. A non-cohesive class may need
to be restructured into two or more smaller classes.
• Relational Cohesion (H): average number of internal relationships per
type:
• H = (R + 1) / N,
R = number of type relationships internal to the package,
N = number of types in the package.
• Classes inside an assembly should be strongly related, the cohesion should
be high. On the other hand, too high values may indicate over-coupling. A
good range is 1.5 ≤ H ≤ 4.0
Presented By : Moutasm Tamimi , 2018
18. Cohesion metrics
• Low Cohesion: Functionalities of a module are independent of each
other.
• High Cohesion: Functionalities of a module are strongly related.
- High cohesion is better situation.
• Readability – (closely) related functions are contained in a single module
• Maintainability – debugging tends to be contained in a single module
• Reusability – classes that have concentrated functionalities are not polluted
with useless functions
• Understand what a class or method does
• Use descriptive names
Presented By : Moutasm Tamimi , 2018
21. Inheritance
• Depth of inheritance tree (DIT) for a class or a structure is its number
of base classes (including System.Object thus DIT ≥ 1).
Types where DIT > 6 might be hard to maintain.
Not a rule since sometime classes inherit from tier classes which have a high
DIT.
E.g., the average depth of inheritance for framework classes which derive from
System.Windows.Forms.Control is 5.3
• Number of children: (NOC) for a class is the number of types that
subclass it directly or indirectly. Number of children for an interface is
the number of types that implement it.
Presented By : Moutasm Tamimi , 2018
23. lack of cohesion of methods
• The single responsibility principle states that
a class should not have more than one
reason to change.
• A high LCOM value generally pinpoints a
poorly cohesive class.
• Types where LCOM > 0.8 and |F| > 10 and
|M| >10 might be problematic. However, it is
very hard to avoid such non-cohesive types
Presented By : Moutasm Tamimi , 2018
24. Association between classes (ABC)
• The association between classes (ABC) is the number of members of
others types that a class directly uses in its the body of its methods.
Presented By : Moutasm Tamimi , 2018
25. Cyclomatic complexity (CC)
• Cyclomatic Complexity (CC) Number of these expressions in the
method body
• “if, while, for, foreach, case, default, continue, goto, &&, ||, catch, ?
: (ternary operator), ?? (nonnull operator)”
• These expressions are not counted:
• “else, do, switch, try, using, throw, finally, return, object creation,
method call, field access”
• CC > 15 are hard to understand, CC > 30 are extremely complex and
should be split into smaller methods (unless generated code)
Presented By : Moutasm Tamimi , 2018
26. IL Cyclomatic Complexity (ILCC)
• ILCC: Number of distinct code offsets targeted by jump/branch IL
instructions. Language independent.
• ILCC is generally larger than CC.
• ILCC( if ) = 1
• ILCC( for ) = 2
• ILCC( foreach ) = 3
• ILCC > 20 are hard to understand, ILCC > 40 are extremely complex and
should be split into smaller methods (unless generated code)
Presented By : Moutasm Tamimi , 2018
28. Speaker Information
Moutasm tamimi
Masters of Software Engineering
Independent Consultant , IT Researcher.
CEO at ITG7.com , IT-CRG.com
Email: tamimi@itg7.com
Click Here
Click HereI T G 7
Click Here
Click HereIT-CRG