Lecture 1: Software Measurement. Marlon Dumas

Size: px
Start display at page:

Download "Lecture 1: Software Measurement. Marlon Dumas"

Transcription

1 Software Economics Fall 2011 Lecture 1: Software Measurement Marlon Dumas (slides by Anton Litvinenko)

2 What is a measure? Way of associating a formal object (e.g. number) and some attribute of a physical object height temperature 2

3 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 3

4 Scales! 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, 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 4

5 What Can You Say? 5

6 What can we say?! Software design: " 10 modules with complexity range " 20 modules with complexity range! Which one is less complex?! Lesson: Not all scales are additive. 6

7 Example: Temperature! Facts: " Steve: today is 40ºF, yesterday was 80ºF " John: today is 4ºC, yesterday was 27ºC! Statements: " Steve: Yesterday was warmer than today " John: Yesterday was warmer than today 7

8 Example: Temperature! Facts: " Steve: today is 40ºF, yesterday was 80ºF " John: today is 4ºC, yesterday was 27ºC! Statements: " Steve: Yesterday was 2x times warmer! Lesson: not all scales are multiplicative 8

9 Nominal Scale! Giving names to objects " Equality! Numbers on t-shirts of football players! Numerical object identifiers " Any unique numbering is similar to any other 9

10 View from 3000 feet :) Nominal Scales T-shirt Numbering OID 10

11 Ordinal Scale! Giving names in particular order " More... than... " Middle element median! Rating of tennis players " Similar: any other rating that retains the order 11

12 All Ordinal Scales Are Nominal T-shirt Numbering Nominal OID Ordinal Grading Top

13 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 13

14 Interval Scales Are Ordinal T-shirt Numbering Grading Nominal Ordinal OID Top 100 Interval Temperature 14

15 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 15

16 Ratio Scales Are Interval T-shirt Numbering Grading Temperature Nominal Ordinal Interval Ratio Gender Top 100 Length Height 16

17 Absolute Scale! Only one way of measuring objects, e.g. by counting the objects themselves! " Similar identity transformation: t(x) = x! Counting: " My team has 5 members " My software is 25 lines of code 17

18 Absolute Scales Are Ratio T-shirt Numbering Grading Temperature Length Nominal Ordinal Interval Ratio Absolute Scales Team Size Gender Top 100 Height 18

19 Exercise 1! Suggest a measure and a scale for " Mass of physical object " Human intelligence " Movies " Cost of cars " Speed of different computers " User-friendliness of a software 19

20 Exercise/Question 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? 20

21 Software Measure is a measure of anything directly related to software or its production Often, Software Metric is used as synonym for Software Measure, although metric has a specific meaning in Maths (e.g. triangle inequality) 21

22 Agenda 1.What is a software metric? 2.Examples of software metrics 1.Most famous :) 22

23 Lines Of Code (LOC) Product Size! 12! 14! 18 23

24 Lines Of Code 24

25 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 25

26 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 26

27 McCabe's Cyclomatic Complexity 27

28 McCabe's Cyclomatic Complexity 2: System.out.println (" ") ; for (Client c : clients ) 4-5: System.out.println (c.getid () + " " + c.getfirstname ()) ;! e = 7! n = 6! p = 1! V(G) = 3 if (clients.size () == 0) 8: System.out.println (" \tnothing ") ; 10 : System.out.println (" ") ; 28

29 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 29

30 Exercise 3! Calculate LOC! Draw a flow graph! Calculate McCabe's cyclomatic complexity Code snippet 30

31 Agenda 1.What is a software metric? 2.Examples of software metrics 1.LOC and McCabe's cyclomatic complexity 2.Object oriented metrics 31

32 Inheritance Metrics! Depth of inheritance tree (DIT) " Depth of the class in the inheritance tree! Number of children (NOC) " Number of immediate descendants A NOC: 3 DIT: 1 B C D NOC: 2 DIT: 2 E F 32

33 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 33

34 Complexity Example RFC = 6, WMC = = 4 34

35 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 35

36 Coupling Example CBO = 2, LCOM = 3 0 = 3 36

37 Coupling Example LCOM = 2 1 = 1 37

38 Agenda 1.What is a software metric? 2.Examples of software metrics 1.LOC and McCabe's cyclomatic complexity 2.Object oriented metrics 38

39 Agenda 1.What is a software metric? 2.Examples of software metrics 1.LOC and McCabe's cyclomatic complexity 2.Object oriented metrics 3.Developer and team metrics 39

40 Developer and Team Metrics! Productivity " How active developers are, how much work is being done! Knowledge! Expertise " How much developers know the software they are working on " What kind of tools and libraries developers use! Team healthiness " Communication and knowledge sharing 40

41 Productivity: Code Churn Metrics! Amount of code changed in the software during the period of time " Churned LOC number of added, modified and deleted lines of code " Churn Count number of changes made to a file " Files Churned number of changed files 41

42 Applications of Code Churn Metrics! Overview of activity and productivity! Increase in relative code churn metrics! increase in defect density " Number of defects per line of code! Vulnerable files have higher code churn metrics " Vulnerability instance of violation of the security policy! Question: Is Productivity additive? Multiplicative? (Hint: The Mythical Man Month) 42

43 Agenda 1.What is a software metric? 2.Examples of software metrics 1. LOC and McCabe's cyclomatic complexity 2. Object oriented metrics 3. Developer and team metrics 4. Project size metrics 43

44 Perfect Hours! One hour of ideal engineering " How many perfect hours in a work day?! Relative measure of effort " How many ideal engineering hours required to complete the feature! Team specific! Applied early " Manual and subjective 44

45 Story Points! Generalization of a perfect hour " Relative measure of effort required to complete the feature! Not tied to time! Team specific! Applied early " Manual and subjective 45

46 Function Points! Will be covered during next workshop 46

47 Agenda 1.What is a software metric? 2.Examples of software metrics 1.LOC and McCabe's cyclomatic complexity 2.Object oriented metrics 3.Object oriented design quality metrics 4.Developer and team metrics 5.Project size metrics 6.Quality metrics 47

48 Quality Metrics! Many different models, checklists " McCall's, FRUPS, ISO 9126 " Functionality, reliability, usability, portability,! Cannot be measured directly! derived from other metrics 48

49 Example: Defect Efficiency Ratio! Efficiency of quality assurance procedures " How many bugs were delivered to customer! DER = E / (E + D) " E errors found before delivery " D defects = errors found after delivery! What would be an ideal situation? 49

50 Agenda 1.What is a software metric? 2.Examples of software metrics 3.Classification of software metrics 50

51 Classification of Software Metrics Subject of measurement 51

52 Subject: Development Process! Measuring the efficiency of process application! On the organizational level strategic purposes! On the project level tactical purposes! Examples of metrics " Length of (development) iteration " Number of changes in requirements " Number of finished tasks " Defect detection percentage 52

53 Subject: Resources! Measuring usage of personnel & resources and their properties! Examples of metrics " Developer competency " Developer fluctuation " Developer productivity and know-how in the project " Maturity of the code written by developer 53

54 Subject: Product! Measuring product attributes " Size, complexity, scalability! Examples of metrics " LOC, commented lines of code, function points " McCabe's cyclomatic complexity " Code coverage with test " Code stability 54

55 Classification Overview What is measured? Metric A Process Resources Product 55

56 Classification of Software Metrics Lines of Code vs Quality 56

57 Direct Metrics! Directly measurable! Examples of metrics: " LOC, function points " McCabe's cyclomatic complexity " Number of requirements 57

58 Indirect Metrics! Not possible to measure directly " Derived from other properties! Examples of metrics " Code quality, code readability " Developer productivity, efficiency " Reliability 58

59 Classification Overview What is measured? Metric A Is it measurable? Process Resources Direct Indirect Product 59

60 Classification of Software Metrics (In)dependency on the measurement context 60

61 Internal Attributes! Measurement context/environment is not relevant! Examples of metrics " LOC " McCabe's cyclomatic complexity " Code coverage with tests 61

62 External Metrics! Measured with respect to environment/context! Examples of metrics " Software reliability " Developer productivity " Source code comprehensibility " Usability 62

63 Classification Overview What is measured? Metric A Is it measurable? Is context dependent? Process Resources Product Direct Indirect Internal External 63

64 Classification Example What is measured? LOC Is it measurable? Is context dependent? Process Resources Product Direct Indirect Internal External 64

65 Exercise 4! We have a tight schedule and we asked two testers Alice and Bob to test 5 software components! Bob reported that he had time to thoroughly test only 1st component and have found totally 20 bugs! Alice reported that she partially tested all components and found 5, 6, 4, 2 and 5 bugs correspondingly! Whose report is more useful? What decisions can you make? 65

66 Question! How do you think where is the highest probability of finding undetected bug? Why? " In components showing LARGE number of known bugs " In components showing SMALL number of known bugs 66

67 Observation "as the number of detected errors in a piece of software increases the probability of the existing of more undetected errors also increases" Glenford Myers, 1976 Bugs tend to cluster! as you find a bug you should stop and write more tests for components where you have found a bug 67

68 Home Reading David Longstreet Function Point Manual 68

69 References Some material in this lecture is inspired by or extracted from:! G. Ford, Measurement theory for software engineers " C. Lange, Metrics in software architecting " M. Gökmen, Software process and project metrics " Lines of code " 69

70 ! McCabe's cyclomatic complexity References II " " " S. Chidamber and C. Kemerer, A metrics suite for object oriented des. " C. Martin, OO Quality design metrics " R. Pressman, Software engineering: a practitioner's approach " More " " " 70