4/6/2011
1
CSE503:
SOFTWARE ENGINEERING
COMPLEXITY, PROVING ADTS
David Notkin
Spring 2011
But first… from today’s Seattle Times
2011.5.4
503 11sp © UW CSE
• D. Notkin
2
“Industry
experts believed they knew where to look
for crackinducing metal fatigue on aging airplanes,
but the inflight rupture of a Southwest Airlines Boeing
737 on Friday has raised concerns about part of the
fuselage they previously thought wasn't vulnerable.
“A
similar hole opened on a Southwest 737 only 21
months ago, and then on an American Airlines 757
last year, raising awareness that metal fatigue can
cause the aluminum skin to separate at the socalled
lap joints, where panels are spliced together
.”
Software complexity
503 11sp © UW CSE
• D. Notkin
3
First, some common
software complexity
measures
Then, why they are weak
measures and (perhaps) a
way forward
From last lecture
–
complexity
in the “why is it hard?” sense
Today: “how complex” is a
piece of software?
Lines of code (LOC, KLOC, MLOC)
503 11sp © UW CSE
• D. Notkin
4
Count the lines, often omitting comments and/or
omitting blank lines
Lines vs. statements
Delivered vs. total (including tests, etc.)
Productivity: LOC/person/time
I’ve seen published numbers ranging from ~2K
8K
LOC/person/year
Sensible?
"I have made this letter longer than usual, because I
lack the time to make it short.” –
Blaise Pascal
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document4/6/2011
2
Halstead software science metrics
503 11sp © UW CSE
• D. Notkin
5
V = N
log
2
(n)
Volume is intended to capture the size of the implementation
Making N choices from the vocabulary
–
assuming that humans do logarithmic search
–
leads to the formula
“The volume of a function should be at least 20 and at most 1000. The volume of a
parameterless oneline function that is not empty; is about 20. A volume greater than
1000 tells that the function probably does too many things.”
[verifysoft.com]
D = ( n1 / 2 )
( N2 / n2 )
Difficulty is proportional to the unique operators and the ratio
of total operands to the number of operands
The intent of the second part is based on a belief that repeated use of operands is more
errorprone
E = V
D
Effort to implement or understand a program
...
n1 = #distinct operators
n2 = #distinct operands
n = n1 + n2
“vocabulary”
N1 = total # of operators
N2 = total # of operands
N = N1 + N2
“length”
Cyclomatic complexity (McCabe)
503 11sp © UW CSE
• D. Notkin
6
Take the CFG and find the number of edges (
E
),
number of nodes (
N
), and the number of connected
components (
P
)
Connected components are subgraphs for which there is a
path between any two vertices
The cyclomatic complexity is
M = E
−
N + 2P
and is
intended to measure the number of linearly
independent paths through a program’s source code
#tests (branch coverage)
M
#tests (path coverage)
Question: should the complexity include method
dispatch in OOP?
Examples
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '11
 DavidNotikin
 cyclomatic complexity, UW CSE, this.elts

Click to edit the document details