18 software metrics (part ii)

31
Software Metrics (Part II)

Upload: tracey-morin

Post on 14-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 1/31

Software Metrics (Part II)

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 2/31

Product Metrics

Product metrics are generally concerned

with the structure of the source code

(example LOC).

Product metrics are metrics that can be

calculated independent of how the

document is produced.

They can be calculated for other documents

too. For example the number of words in a

requirements specification.

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 3/31

McCabe’s Cyclomatic Number  

McCabes cyclomatic number (also called

McCabe’s complexity measure), after LOC, is one

of the most commonly used software metrics.

It was introduced in 1976.

It is based on graph theory’s cyclomatic

number.

Thomas McCabe Sr.

http://reengineer.org/stevens/previous.htm

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 4/31

 A Little Graph Theory

 A graph G is planar if it can be drawn on a plane

so that none of its edges cross.

Planar or not?

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 5/31

Strongly Connected Graphs

 A directed graph G is

strongly connected if 

thee is a path from any

node to any other node.

Strongly Connected

Not Strongly Connected

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 6/31

Weakly Connected Graphs

 A graph G is weakly

connected, if every

node can reach every

other node and youdon’t care which way

the directed edges

point.

Weakly Connected

Not Weakly Connected

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 7/31

Strongly Connected Components

 A strongly connected

component of a graph

G is a maximal

subgraph of G that isstrongly connected.

What are the strongly

connected component?

2

1

3

4 5

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 8/31

Euler’s Theorem 

e = the number of edges

n = the number of nodes

r = the number of regions formed by the graph

Leonhard Euler (1707-1783) proved that for a

planar graph G:

where

2 = n – e + r 

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 9/31

Euler’s Theorem 

n =

2

1

3

4 5

e =

r =

n – e + r =

5

6

3

2

Consider the graph below

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 10/31

McCabe’s Cyclomatic Number  

2 = n – e + r can be rewritten to find the

number of regions in a planar graph

knowing the number of nodes and edges:

r = e – n + 2

McCabe used the number of regions formedby a control flow graph as his software

metric and named it “McCabe’s Complexity

Measure” 

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 11/31

McCabe’s Cyclomatic Number  

McCabe generalized the number for graphs

that contained more than one strongly

connected component as:

Cyclomatic number (C) = e – n + 2p

where p = number of strongly connectedcomponents

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 12/31

McCabe’s Cyclomatic Number  

Find McCabe’s cyclomatic number for the

following control flow graph:

2

1

3

4 5

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 13/31

Calculate McCabe’s

cyclomatic number 

for the following

code:

 /* main routine */x := 1;while (x = 1) {

x := 2;test ( x, 1 );x := 3;} // End while

while (x = 1) {x := 4;x := 5;test ( x, 2 );} //End while

While (x = 1) {x := 6;if (x = 7) x := 8;else test ( x, 3 );} // End while

} // End main

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 14/31

Threshold

McCabe analyzed large projects and found

that when the cyclomatic number for a

module exceeds 10, there is a history of 

many more errors and difficulties in

maintenance.

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 15/31

Halstead Measure (1977)

Maurice Halstead did his work in the late

1960’s and early 1970’s. 

He was a pioneer in software metrics (aswas McCabe).

His goal was to find out what contributed to

software complexity.

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 16/31

Halstead Metrics

 A program is considered to be a collection of 

tokens.

Tokens are either operators or operands.

Operands were tokens that had a value

(typically variables or constants).

Everything else is an operator (commas

parenthesis, arithmetic operators, i.e. all the

C++ operators)

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 17/31

Halstead Metrics

 All tokens that occur as pairs, triples, etc.

count as one token (example: parenthesis).

Halstead did not count declarations, input or output statements, or comments do not

count as tokens.

Most organizations currently count all parts

of a program.

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 18/31

Halstead Metrics

The count of unique operators is ή1 (eta

one) and the count of unique operands is ή2 

(eta two).

z = 0;

While x > 0

z = z + y;x = x – 1

End-while;

Print (z);

Consider the code below:

Operators:

= While; + -> Print ( )

Operands:

ή1 = 8

z 0x y 1ή2 = 5

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 19/31

Halstead Metrics

The length (N) of the program is the totalcount of operators and operands.

For example, for:

z = 0;

While x > 0

z = z + y;

x = x – 1

End-while;

Print (z);

Number of operands = 11

Number of operators = 14

N = 25

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 20/31

Halstead Metrics

The Estimate of Length (est N or N_hat) isdefined as:

Est N = ή1 * log2 ή1 + ή2 * log2 ή2

This formula can be used to estimate the total

number of tokens, based on the number of 

different tokens.

The author of your book has found that if N and

Est N differ by more than 30%, then it may not be

reasonable to apply other software science

measures.

Then again, it may be!

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 21/31

Halstead Metrics

Halstead’s measure:

Est N = ή1 * log2 ή1 + ή2 * log2 ή 

is based on Claude Shannon’s formula for entropy (the amount of information in

something) in information theory.

H = n * log S whereS 

is the number of possible symbols, and n the number of 

symbols in a transmission

April 30, 1916  – 

February 24, 2001 

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 22/31

Halstead Metrics

For the code:

z = 0;

While x > 0z = z + y;

x = x – 1

End-while;

Print (z);

ή1 = 8

ή2 = 5

Est N = 8 log2 8 + 5 log2 5

Est N = 8 * 3 + 5 * 2.32

Est N = 35.6N = 25

difference = 10.6 / 35.6 = 29.8%

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 23/31

Volume

The volume of a program is related to the

number of bits needed to encode the

program

The volume of a program is defined as:

V = N * log2(ή1 + ή2) 

For our sample code:

V = 25 * log2(8 + 5)= 25 *3.7 = 92.5

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 24/31

Potential Volume

The potential volume is the minimal size of 

a solution solved in any language.

Halstead defined the potential volume as:

V* = (2 + ή2*) log2(ή2*) 

Where ή2* is the minimum set of operands

needed to implement the algorithm in any

language .

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 25/31

Implementation Level

The implementation level is defined as:

L = Potential Volume / Volume = V* / V

This relates to how close the current

implementation is to the minimal

implementation.

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 26/31

Henry –Kafura Information Flow

Sallie Henry and Dennis Kafurn developed a

software metric to measure the intermodule

complexity of code.

For a module, a count is made of all the

information flows into the module (fan-ins)

and all the information flows out of themodule (fan-outs).

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 27/31

Henry –Kafura Information Flow

The information flows include:Parameters

Global variables

Inputs and outputs

HK = weight * (out * in)2

Where the weight is determined by the

size of the module and the HK’s are

summed over all modules.

Their formula is (for a single module)

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 28/31

 Advantages: Henry –Kafura

Information Flow

They look at higher level complexity, while

McCabe looks at lower level complexity.

McCabe’s complexity can only be applied

when you have detail source code or 

pseudo-code.

Henry and Kafura’s complexity can be

applied during design phase and also atscoping phase if proper information flow

block diagrams are drawn

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 29/31

Disadvantages: Henry –Kafura

Information Flow

If fan-in or fan-out is zero the whole

complexity will become zero.

Just imagine you are using Henry and

Kafura’s complexity and fan-in or fan-out is

zero the quotation is zero Dollars.

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 30/31

Disadvantages: Henry –Kafura

Information Flow

The length factor is a completely different

attribute.

Multiplication of the factor with complexityhas been questioned by experts.

 Arthimetic calculations can be performed on

measurements of similar type.

Example adding 1 litre + 10 volts will yield

nothing sensible

7/29/2019 18 Software Metrics (Part II)

http://slidepdf.com/reader/full/18-software-metrics-part-ii 31/31

The End