We use static code analysis tools more often these days that create great reports and funky graphs. But do we understand what it all means?
Software metrics tends to be magic numbers for a lot of people, but they don’t really have to be. Seb will introduce you to a few basic, the most popular software metrics and tools. He will explain to you what they mean and how you can use them to produce better software.
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
PHP Forum Paris 2012: Magic behind the numbers. Software metrics in practice
1. Magic
behind
the
numbers
So.ware
metrics
in
prac&ce
Sebas&an
Marek,
So.ware
Architect
2. • a
Pole
living
in
Sheffield
• over
12
years
in
development
• Pascal,
C++,
PHP,
perl,
python,
Java
• co-‐author
of
2
PHP
books
• big
fan
of
process
automa&on
• TDD
and
CI
• occasionally
contributes
to
open
source
projects
• wants
to
be
a
knight
@proofek
3. • What
I
will
be
talking
about
• Code
metrics
• Design
metrics
• What
I
will
not
be
talking
about
• Project
metrics
Agenda
6. “It is the mapping of
a particular
characteristic
of a measured entity
to a numerical value”
Source: Object-Oriented Metrics
in Practice
What
is
a
metric?
7. “Good design quality metrics are not
necessarily indicative of good designs.
Likewise, bad design quality metrics are
not necessarily indicative of bad
designs”
Source: Jdepend Docs
So.ware
design
8. • Obsolete
documenta&on
• Convoluted
design
• Intensive
patch
mechanism
(hacking)
• Large
size
• Severe
duplica&on
• Obsolete
parts
(dead
code)
• Long
build
&mes
• Loss
of
original
developers
System
maintenance
9. • CLOC
–
comment
lines
of
code
• ELOC
–
executable
lines
of
code
• LOC
–
lines
of
code
• NCLOC
–
non
comment
lines
of
code
• NOP
–
number
of
packages
• NOC
–
number
of
classes
• NOM
–
number
of
methods
Simple
metrics
29. “NPATH is an objective measure of
software complexity related to
the ease with which software
can be comprehensively tested”
Edgar H. Sibley
NPATH
–
acyclic
execu&on
path
complexity
30. expressions Number of && and || operators in expression
if NP(<if-range>)+NP(<expr>)+1
if-else NP(<if-range>)+NP(<else-range>)+NP(<expr>)
while NP(<while-range>)+NP(<expr>)+1
for NP(<for-range>)+NP(<expr1>)+NP(<expr2>)+
NP(<expr3>)+1
break 1
continue 1
return 1
sequential 1
function call 1
NPATH
–
acyclic
execu&on
path
complexity
31. class Foo {
public function example() {
if ($a == $b) {
if ($a1 == $b1) {
fiddle();
} else {
fiddle();
}
}
if ($e == $f && $g == $z) {
for ($n = 0; $n < $h; $n++) {
fiddle();
}
}
return true;
}
}
NPATH
–
example
32. class Foo {
public function example() {
if ($a == $b) {
if ($a1 == $b1) {
fiddle();
} else { 3
fiddle();
}
}
if ($e == $f && $g == $z) {
for ($n = 0; $n < $h; $n++) {
fiddle(); 4
}
}
return true; 1
}
}
NPATH
–
example
48. “We
believe
that
soIware
metrics,
in
general,
are
just
tools.
No
single
metric
can
tell
the
whole
story;
it’s
just
one
more
data
point.
“
“Metrics
are
meant
to
be
used
by
developers,
not
the
other
way
around
–
the
metric
should
work
for
you,
you
should
not
have
to
work
for
the
metric.
“
“Metrics
should
never
be
an
end
unto
themselves.
Metrics
are
meant
to
help
you
think,
not
to
do
the
thinking
for
you.”
• Alberto
Savoia
Summary