Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 307 Introduction to Software Engineering Lecture 11. Software Metrics

Slide 2

Slide 2 text

Feedback From Assignment 03

Slide 3

Slide 3 text

Code 3 https://github.com/CSC3100/App-Paint/

Slide 4

Slide 4 text

Single Responsibility • E a ch cl a ss or function should h a ve one, a nd only one, job. • Keep functions focused on a single t a sk. • Bre a k down your code into sm a ller, reus a ble modules or functions. • Ensure e a ch module or function h a s a cle a r, well-de f ined purpose. • 4

Slide 5

Slide 5 text

Clean Your Code!

Slide 6

Slide 6 text

Maven File and Directories 6

Slide 7

Slide 7 text

About MQTT 8

Slide 8

Slide 8 text

Code Metrics

Slide 9

Slide 9 text

Software Metrics Size

Slide 10

Slide 10 text

Size Metrics • LOC – Lines of Code Metric. Including lines of a single br a ce or p a renthesis • LOC a re used to cre a te time a nd cost estim a tes. • LOC a re a tr a cking tool to me a sure the degree of progress on a module or project. • An experienced developer c a n g a ge a LOC estim a te b a sed upon knowledge of p a st productivity on projects. 12

Slide 11

Slide 11 text

Size Metrics • eLOC – e ff ective Lines of Code Metric. Only code st a tements • An e ff ective line of code or eLOC is the me a surement of a ll lines th a t a re not comments, bl a nks or st a nd a lone br a ces or p a renthesis. These c a n in f l a te LOC metrics by 20 to 40 percent. • This metric more closely represents the qu a ntity of work performed. 13

Slide 12

Slide 12 text

Size Metrics • lLOC – logic a l Lines of Code Metric. • These st a tements a re termin a ted with a semi-colon. • The control line for the "for" loop cont a in two semi-colons but a ccounts for only one semi colon. 14

Slide 13

Slide 13 text

Example 15

Slide 14

Slide 14 text

Test Yourselves

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Software Metrics Complexity

Slide 23

Slide 23 text

Function Metrics • Cyclomatic Complexity. It is a quantitative measure of the number of linearly independent paths. • P a ths occur when "while,” "for,” "if,” "c a se," a nd "goto" keywords a ppe a r within the function. • If the source code cont a ined no control f low st a tements (condition a ls or decision points), the complexity would be 1 • If the code h a d one single-condition IF st a tement, there would be two p a ths through the code: one where the IF st a tement ev a lu a tes to TRUE a nd a nother one where it considers to be FALSE. • Two nested single-condition IFs, or one block with two conditions, would produce a complexity of 3. 25

Slide 24

Slide 24 text

Cyclomatic Complexity 26 CC = Edge - Node + 2 Or CC = ConditionalNodes + 1

Slide 25

Slide 25 text

Cyclomatic Complexity i = 0; n=4; while (i

Slide 26

Slide 26 text

Complexity Number Meaning 1-10 Structured and well written code High Testability Cost and Effort is less 10-20 Complex Code Medium Testability Cost and effort is Medium 20-40 Very complex Code Low Testability Cost and Effort are high >40 Not at all testable Very high Cost and Effort Cyclomatic Complexity 28

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Structural Metrics Abstractness Instability

Slide 35

Slide 35 text

Is this a good design? 37

Slide 36

Slide 36 text

Abstractness • It is the degree to which a cl a ss or p a ck a ge emph a sizes a bstr a ction over concrete implement a tion • It is a v a lue 0 to 1: • For p a ck a ges, It is the r a tio of a bstr a ct cl a sses or interf a ces to the tot a l number of cl a sses within a p a ck a ge. • For cl a sses, It is 0 for a concrete cl a ss a nd 1 for a n interf a ce or a bstr a ct cl a sses 38

Slide 37

Slide 37 text

Instability • Indic a tes whether: ( a ) the item is m a inly used by others (st a ble – h a rd to ch a nge); or (b) it m a inly depends on other items (in-st a ble – ch a nge a ble). • It is a v a lue between 0 a nd 1: • 0 only incoming dependencies to • 1 (only outgoing dependencies). 39

Slide 38

Slide 38 text

Distance • Dist a nce: how f a r a p a ck a ge is a w a y from the M a in Sequence • D = A + I – 1 • V a lues -1 to 1 • Absolute Dist a nce |D| 40

Slide 39

Slide 39 text

Distance 41 Abstract Concrete Stable Hard to Change Only incoming dependencies Unstable Changeable Only outgoing dependencies the main sequence Painful Useless 0 1 1 0 Instability Abstractness

Slide 40

Slide 40 text

Is this a good design? 42

Slide 41

Slide 41 text

project3.common.model project3.client.UI project3.server.controller

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Questions 45

Slide 44

Slide 44 text

Lab

Slide 45

Slide 45 text

Reminder 47 Calculate the structural metrics for classes here:

Slide 46

Slide 46 text

CSC 307 Introduction to Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Summer 2024 Copyright. These slides can only be used as study material for the class CSC307 at Cal Poly. They cannot be distributed or used for another purpose.