Slide 1

Slide 1 text

jgs CSC 309 Software Engineering II Lecture 03: Software Metrics: Code Quality Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227

Slide 2

Slide 2 text

jgs Previously …

Slide 3

Slide 3 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 3 § Knowing what is inside your source code is the first step in assessing the quality of the software product. § Knowing the quantity of work performed in generating the source code is the first step in determining the productivity of your software team. Software Metrics

Slide 4

Slide 4 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 4 code Key Ideas CSC 309 idea requirements architecture design quality measure

Slide 5

Slide 5 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 5 Stable Abstraction Principle Abstract concrete Stable Hard to Change Only incoming dependencies Unstable Changeable Only outgoing dependencies

Slide 6

Slide 6 text

jgs Software Metrics Size

Slide 7

Slide 7 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 7 Metrics Size LOC eLOC lLOC Understandability Comments Whitespaces Complexity Average, Max, Min LOC Interface Complexity Cyclomatic Complexity Software Metrics

Slide 8

Slide 8 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 8 § LOC – Lines of Code Metric. Including lines of a single brace or parenthesis § LOC are used to create time and cost estimates. § LOC are a tracking tool to measure the degree of progress on a module or project. § An experienced developer can gage a LOC estimate based upon knowledge of past productivity on projects. Size Metrics

Slide 9

Slide 9 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 9 § eLOC – effective Lines of Code Metric. Only code statements § An effective line of code or eLOC is the measurement of all lines that are not comments, blanks or standalone braces or parenthesis. These can inflate LOC metrics by 20 to 40 percent. § This metric more closely represents the quantity of work performed. Size Metrics

Slide 10

Slide 10 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 10 § lLOC – logical Lines of Code Metric. § These statements are terminated with a semi-colon. § The control line for the "for" loop contain two semi-colons but accounts for only one semi colon. Size Metrics

Slide 11

Slide 11 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 11 Example

Slide 12

Slide 12 text

jgs Software Metrics Complexity

Slide 13

Slide 13 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 13 § Cyclomatic Complexity. It is a quantitative measure of the number of linearly independent paths. § Paths occur when "while,” "for,” "if,” "case," and "goto" keywords appear within the function. § If the source code contained no control flow statements (conditionals or decision points), the complexity would be 1 § If the code had one single-condition IF statement, there would be two paths through the code: one where the IF statement evaluates to TRUE and another one where it is considered to be FALSE. § Two nested single-condition IFs, or one block with two conditions, would produce a complexity of 3. Function Metrics

Slide 14

Slide 14 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 14 Cyclomatic Complexity CC = Edge - Node + 2 Or CC = ConditionalNodes + 1

Slide 15

Slide 15 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 15 i = 0; n=4; while (i

Slide 16

Slide 16 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 16 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

Slide 17

Slide 17 text

jgs Test Yourselves

Slide 18

Slide 18 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 18 Hello World

Slide 19

Slide 19 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 19 BubbleSort Iterativo

Slide 20

Slide 20 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 20 Recursive BubbleSort

Slide 21

Slide 21 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 21 In Order Traversal

Slide 22

Slide 22 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 22 Example

Slide 23

Slide 23 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 23 Example

Slide 24

Slide 24 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 24 Example

Slide 25

Slide 25 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 25 Questions

Slide 26

Slide 26 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 26 Chapter 24 Reference

Slide 27

Slide 27 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 27 Office Hours Tuesday and Thursday 3 - 5 pm But an appointment required Sent me an email – [email protected]

Slide 28

Slide 28 text

jgs

Slide 29

Slide 29 text

jgs CSC 309 Software Engineering II Lab 02: Tower of Hanoi Quality Metrics Dr. Javier Gonzalez-Sanchez [email protected] Building 14 -227

Slide 30

Slide 30 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 31 Step 1 Calculate Code Metrics (LOC, eLOC, lLOC, CC) Per Class for https://github.com/javiergs/TowerOfHanoi

Slide 31

Slide 31 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 32 Step 2 Create a UML Class Diagram for https://github.com/javiergs/TowerOfHanoi

Slide 32

Slide 32 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 33 Step 3 Calculate Structural Metrics (A, I, D) Per Class https://github.com/javiergs/TowerOfHanoi

Slide 33

Slide 33 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 34 Step 4 Write a paragraph about what you think of the metrics. What do the metrics state about the code? – explain with your own words (good, bad, unknown) https://github.com/javiergs/TowerOfHanoi

Slide 34

Slide 34 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 35 Step 5 Compile and run the code. You will notice an error when moving disks as follows:

Slide 35

Slide 35 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 36 Step 5 repeat several times { move disk 1 from Poll 1 to Poll 3. move disk 1 from Poll 3 back to Poll 1 } // Notice how each time the disk is drawn // upper and upper like floating in the poll // Why?

Slide 36

Slide 36 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 37 Step 5 Can you fix it?

Slide 37

Slide 37 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 38 Step 5 How many files need to be edited? How many lines are to be added? How many lines are to be modified or removed? Elaborate an explanation (either way)

Slide 38

Slide 38 text

jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 39 Let’s Work

Slide 39

Slide 39 text

jgs CSC 309 Software Engineering II Javier Gonzalez-Sanchez, Ph.D. [email protected] Winter 2024 Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly. They cannot be distributed or used for another purpose.