Software Measurement Software Economics 2010
Anton Litvinenko Co-founder and CTO at Metrics tracking kit for software development
Key competence:  software measurement and metrics 9 years of software development at Programeter, Mobi, and MicroLink
MSc in computer science at Tartu University
Agenda What is a software metric?
Are software metrics “ good ” or “ bad ”?
What is a “ measure ”?
What is a “measure”? “ Way of associating a  number  with some  attribute of a physical object ” height -> meters temperature -> degrees Celsius
What is “measure”? One-to-one mapping  between  physical  objects and  formal  objects (e.g numbers)
Same Stuff Formally Relational System  – tuple consisting of Set of objects ( e.g. collections of apples )
Relations on these objects ( e.g. more, equal )
Binary operations on these objects ( e.g. combine, put together ) What would be the corresponding formal relational system?
Relationships and Operations Apples:  Steve Jobs has 7 apples
Steve Ballmer has 4 apples Jobs has more apples
Jobs and Ballmer can cooperate and put their apples together to have a larger pile
We defined a “ complete transition ” from “ real world ” into “ formal world ”
Same Stuff Formally... again Let A be a relational system of  physical objects  (e.g. apples)
B be a relational system of  formal objects  ( e.g.  numbers)
m be a measure from A to B then
Tuple  A ,  B  and  m  is a  scale  if Relations from A equivalent to relations from B
For each operator in A there is a corresponding operator in B
Why is this important?
What Can You Say?
Why is this important? Software design: 10 modules with complexity 20 – 30 range
20 modules with complexity 10 – 30 range Which one is less complex?
We don't have intuition for such cases
Intelligence Barrier
Example: Temperature Facts : Steve : today is 40 ºF, yesterday was 80ºF
Anton : today is 4ºC, yesterday was 27ºC Statements : Steve :  Yesterday was warmer than today
Anton :  Yesterday was warmer than today
Example: Temperature Facts : Steve : today is 40 ºF, yesterday was 80ºF
Anton : today is 4ºC, yesterday was 27ºC Statements : Steve :  Yesterday was 2x times warmer Is this a  meaningful  statement about temperature?
Statement is  meaningful  when it gives  same result  on  all similar  scales
Scales  are  similar  when there is a  transformation  from one scale to another that  retains all defined relations and operations
Nominal Scale Giving “ names ” to objects Equality Gender Any naming is similar to any other Numbers on t-shirts of football players Any unique numbering is similar to any other
View from 3000 feet :) Nominal Scales Gender T-shirt Numbering
Ordinal Scale Giving “ names ” in  particular order More .... than ....
Middle element –  median Rating of tennis players Similar: any other rating that retains the order
All Ordinal Scales Are Nominal Nominal Ordinal Gender T-shirt Numbering Top 100 Grading
Interval Scale Assigning  numbers  so that  interval is also meaningful Both  median  and  arithmetic mean
Similar – reachable via  positive linear transformation :  t(x) = ax + b Temperature in Celsius scale Similar: Fahrenheit scale
Interval Scales Are Ordinal Nominal Ordinal Interval Gender T-shirt Numbering Top 100 Grading Temperature
Ratio Scale Ratio  of two measures is  meaningful All statistical measures
Similar – reachable via positive linear transformation in form of  t(x) = ax Length, height, ... Similar: Imperial units
Ratio Scales Are Interval Nominal Ordinal Interval Ratio Gender T-shirt Numbering Top 100 Grading Temperature Length Height
Absolute Scale Only one way of measuring objects ! Similar – identity transformation:  t(x) = x Counting:  My team has 5 members
My software is 25 lines of code
Absolute Scales Are Ratio Nominal Ordinal Interval Ratio Absolute Scales Gender T-shirt Numbering Top 100 Grading Temperature Length Height Team Size
Exercise 2 Cost  is usually a measure with  ratio scale
Quality  is only  ordinal  (rarely interval)
Judgment in terms of value Quality per unit of cost
Should we pay 2x for 2x quality?  Combining  cost measure on a  ratio scale  with quality measure on  ordinal scale ,  what scale do you get ?
In This Course:  Metric = Measure
Software Metric  is a  measure  of anything directly related to  software  or its  production
Agenda What is a software metric?
Examples of software metrics Most famous :)
Can anybody name any software metric?
Lines Of Code (LOC) – Product Size 12 14 18
Lines Of Code
Lines Of Code – Summary Accurate, easy to measure How to interpret ... Empty lines
Comments
Several statements on one line Language dependent
Doesn't respect complexity and content
McCabe's Cyclomatic Complexity Thomas McCabe, 1976
Complexity of a program Number of linearly independent paths through a function
Usually calculated using flow graph V(G) = e – n + 2p e  – num of edges,  n  – num of vertices,  p  – num of unconnected parts of graph
McCabe's Cyclomatic Complexity
McCabe's Cyclomatic Complexity e = 7
n = 6
p = 1
V(G) = 3
Cyclomatic Complexity – Summary Automated
Maintainability V(G) > 10  ->  Probability of defects rises Testability V(G) is an upper bound for the branch coverage Each control structure was evaluated both to true and false V(G) is a lower bound for the path coverage All possible paths were executed Doesn't respect other types of complexity Data structure, data flow, interfaces
Exercise 3 Calculate  LOC
Draw a  flow graph
Calculate  McCabe's cyclomatic complexity Code snippet
Agenda What is a software metric?
Examples of software metrics LOC and McCabe's cyclomatic complexity
Object oriented metrics
Object Oriented Metrics Shiyam Chidamber  and  Chris Kemerer , 1994 Metrics based on firm  theoretical basis  and experience of professional software developers
Measure unique aspects of the  object oriented  approach
Inheritance Metrics Depth of inheritance tree (DIT) Depth of the class in the inheritance tree Number of children (NOC) Number of immediate descendants NOC: 2 DIT: 2 NOC: 3 DIT: 1
Complexity Weighted method count (WMC) Sum of McCabe's cyclomatic complexities of all methods Response for a class (RFC) Number of public methods in a class and methods directly called by these
Complexity – Example RFC = 6, WMC = 1 + 2 + 1 = 4
Coupling Coupling between object classes (CBO) Number of classes given class is coupled to Lack of cohesion in methods (LCOM) Number of method pairs that do not share instance variables vs number of methods that share at least one instance variable
Coupling – Example CBO = 2, LCOM = 3 – 0 = 3
Coupling – Example LCOM = 2 – 1 = 1
Agenda What is a software metric?
Examples of software metrics LOC and McCabe's cyclomatic complexity
Object oriented metrics
Object oriented design quality metrics
Object Oriented Design Bad design symptoms: Rigidity, fragility, immobility, viscosity Class design principles Open closed principle ,  Liskov substitution principle , ... Package architecture principles Stable dependencies principle ,  Stable abstractness principle , …
OO Design Quality Metrics Robert Martin  (aka Uncle Bob) , 1994
Measure  quality  of an  object oriented design
Can we divide dependencies into “ good ” and “ bad ”? Dependencies Between Classes
Dependencies Stable  (good) vs  unstable  (bad) class
Stable No need to change = independent
Hard to change = many dependents = responsible Unstable Depends on many = dependent
Easy to change = no dependents = irresponsible
Class Category Class category  – group of highly cohesive classes Closed and open to changes together
Reused together
Same goal Packages  in Java,  namespaces  in C#
Dependency Metrics Afferent Coupling (Ca)  – number of classes outside the category depending on the classes inside the category Incoming  dependencies Efferent Coupling (Ce)  – number of classes inside the category depending on the classes outside the category Outgoing  dependencies
Example - Coupling Package One Package Two Package Three Ca(Package One) = 1, Ce(Package One) = 2
Instability (I) Ratio of  outgoing dependencies  to  total number of dependencies I = Ce / (Ca + Ce)
Stable  -> I = 0 -> Ce = 0
Unstable  -> I = 1 -> Ca = 0, Ce > 0
Should all categories be  stable ?
Why a  stable  category needs to be  extensible ? How?
Abstractness (A) Degree to which a category is abstract Ratio of  abstract classes  to the  total number of classes  in category Completely abstract  -> A = 1 -> all classes are abstract
Completely concrete  -> A = 0 -> no abstract classes in category
Is there a relationship between  Instability  and  Abstractness ?
Main Sequence
Distance From Main Sequence D' = |A + I – 1| Normalized to range from [0, 1]
Agenda What is a software metric?
Examples of software metrics LOC and McCabe's cyclomatic complexity
Object oriented metrics
Object oriented design quality metrics
Developer and team metrics
Developer and Team Metrics Productivity How active developers are, how much work is being done Knowledge How much developers know the software they are working on Expertise What kind of tools and libraries developers use Team “healthiness” Communication and knowledge sharing
Productivity: Code Churn Metrics Amount of code changed in the software during the period of time

Software Measurement: Lecture 1. Measures and Metrics