measure and improve code quality. using automation

86
Measure and improve code quality Using automation

Upload: vladimir-korolev

Post on 21-May-2015

79 views

Category:

Software


1 download

DESCRIPTION

Slides from my talk given at MCJUG on 9/17/2014 on measuring and improving code quality using tools such as Sonar.

TRANSCRIPT

Page 1: Measure and Improve code quality.  Using automation

Measure and improvecode quality

Using automation

Page 2: Measure and Improve code quality.  Using automation

About myself

MCJUG 2 / 42

Page 3: Measure and Improve code quality.  Using automation

Vlad Korolev

Been doing software development for 20+ years

Have seen (and wrote) code of varying quality

Personally experienced many problems discussed in this talk

MCJUG 3 / 42

Page 4: Measure and Improve code quality.  Using automation

What is Code Quality?

MCJUG 4 / 42

Page 5: Measure and Improve code quality.  Using automation

What is Quality?

MCJUG 5 / 42

Page 6: Measure and Improve code quality.  Using automation

David Garvin

Five Dimensions of Quality

1 Transcendental

2 Product

3 User

4 Manufacturing

5 Value

MCJUG 6 / 42

Page 7: Measure and Improve code quality.  Using automation

Transcendental

Plato

A characteristic of an object that could not be described. Butcould be learned when one is exposed to a succession of highquality objects.

MCJUG 7 / 42

Page 8: Measure and Improve code quality.  Using automation

Transcendental

Aristotle

Quality is not an act, but a habit.

MCJUG 7 / 42

Page 9: Measure and Improve code quality.  Using automation

Transcendental

Robert Pirsig

I think there is such a thing as Quality, but that as soon as you tryto define it, something goes haywire. You can’t do it.

MCJUG 7 / 42

Page 10: Measure and Improve code quality.  Using automation

Transcendental

Pirsig

No way to explain, but everybody knows it through repeatedexposure to low / high quality product

MCJUG 7 / 42

Page 11: Measure and Improve code quality.  Using automation

Product: Precise measurement of known variable

Ice Cream

More butterfat → higher quiality

MCJUG 8 / 42

Page 12: Measure and Improve code quality.  Using automation

Product: Precise measurement of known variable

Persian rugs

More knots per square inch → higher quiality

MCJUG 8 / 42

Page 13: Measure and Improve code quality.  Using automation

User

More desirable products are of higher quality.

MCJUG 9 / 42

Page 14: Measure and Improve code quality.  Using automation

User

Better selling products are of higher quality.

MCJUG 9 / 42

Page 15: Measure and Improve code quality.  Using automation

Manufacturing

Conformance to well defined standard.

MCJUG 10 / 42

Page 16: Measure and Improve code quality.  Using automation

Manufacturing

Lower variance → higher quality.

MCJUG 10 / 42

Page 17: Measure and Improve code quality.  Using automation

Value : Monetary

More expensive products are of higher quality.

MCJUG 11 / 42

Page 18: Measure and Improve code quality.  Using automation

Value : Monetary

Ferrari is of higher quality than Pinto.

MCJUG 11 / 42

Page 19: Measure and Improve code quality.  Using automation

What is Code Quality?

MCJUG 12 / 42

Page 20: Measure and Improve code quality.  Using automation

Code Quality

External

Internal

MCJUG 13 / 42

Page 21: Measure and Improve code quality.  Using automation

External Code Quality

MCJUG 14 / 42

Page 22: Measure and Improve code quality.  Using automation

External Code Quality

MCJUG 14 / 42

Page 23: Measure and Improve code quality.  Using automation

External Code Quality

MCJUG 14 / 42

Page 24: Measure and Improve code quality.  Using automation

External Code Quality

MCJUG 14 / 42

Page 25: Measure and Improve code quality.  Using automation

External Code Quality

MCJUG 14 / 42

Page 26: Measure and Improve code quality.  Using automation

External Code Quality

MCJUG 14 / 42

Page 27: Measure and Improve code quality.  Using automation

External Code Quality

MCJUG 14 / 42

Page 28: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down2 The system is crediting wrong accounts3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 29: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down2 The system is crediting wrong accounts3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 30: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down2 The system is crediting wrong accounts3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 31: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down2 The system is crediting wrong accounts3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 32: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down2 The system is crediting wrong accounts3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 33: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down

2 The system is crediting wrong accounts3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 34: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down2 The system is crediting wrong accounts

3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 35: Measure and Improve code quality.  Using automation

External Code Quality

Ad hoc tests

QA Tests

Regression tests

User reports

Your boss comes up to you saying :

1 All systems are down2 The system is crediting wrong accounts3 The system is delivering messages to the wrong users

MCJUG 15 / 42

Page 36: Measure and Improve code quality.  Using automation

Internal Code Quality

When you’re a carpenter making a beautiful chest of drawers,you’re not going to use a piece of plywood on the back, eventhough it faces the wall and nobody will ever see it. Youll know itsthere, so youre going to use a beautiful piece of wood on the back.For you to sleep well at night, the aesthetic, the quality, has to becarried all the way through.

Steve Jobs

MCJUG 16 / 42

Page 37: Measure and Improve code quality.  Using automation

Internal Code Quality

How do we measure it?

What’s our equivalent of plywood?

MCJUG 17 / 42

Page 38: Measure and Improve code quality.  Using automation

Internal Code Quality

How do we measure it?

What’s our equivalent of plywood?

MCJUG 17 / 42

Page 39: Measure and Improve code quality.  Using automation

7 Axes of Code Quality

Bad Patterns [ Bugs ]

Bad Style [ Coding Rules ]

Tests / Tests coverage

Duplicated Code [ Cut and paste ]

Comments

Architecture

Lack of Cohesion of MethodsCicular dependencies

Complexity

God classesGod methods

MCJUG 18 / 42

Page 40: Measure and Improve code quality.  Using automation

7 Axes of Code Quality

Bad Patterns [ Bugs ]

Bad Style [ Coding Rules ]

Tests / Tests coverage

Duplicated Code [ Cut and paste ]

Comments

Architecture

Lack of Cohesion of MethodsCicular dependencies

Complexity

God classesGod methods

MCJUG 18 / 42

Page 41: Measure and Improve code quality.  Using automation

7 Axes of Code Quality

Bad Patterns [ Bugs ]

Bad Style [ Coding Rules ]

Tests / Tests coverage

Duplicated Code [ Cut and paste ]

Comments

Architecture

Lack of Cohesion of MethodsCicular dependencies

Complexity

God classesGod methods

MCJUG 18 / 42

Page 42: Measure and Improve code quality.  Using automation

7 Axes of Code Quality

Bad Patterns [ Bugs ]

Bad Style [ Coding Rules ]

Tests / Tests coverage

Duplicated Code [ Cut and paste ]

Comments

Architecture

Lack of Cohesion of MethodsCicular dependencies

Complexity

God classesGod methods

MCJUG 18 / 42

Page 43: Measure and Improve code quality.  Using automation

7 Axes of Code Quality

Bad Patterns [ Bugs ]

Bad Style [ Coding Rules ]

Tests / Tests coverage

Duplicated Code [ Cut and paste ]

Comments

Architecture

Lack of Cohesion of MethodsCicular dependencies

Complexity

God classesGod methods

MCJUG 18 / 42

Page 44: Measure and Improve code quality.  Using automation

7 Axes of Code Quality

Bad Patterns [ Bugs ]

Bad Style [ Coding Rules ]

Tests / Tests coverage

Duplicated Code [ Cut and paste ]

Comments

Architecture

Lack of Cohesion of MethodsCicular dependencies

Complexity

God classesGod methods

MCJUG 18 / 42

Page 45: Measure and Improve code quality.  Using automation

7 Axes of Code Quality

Bad Patterns [ Bugs ]

Bad Style [ Coding Rules ]

Tests / Tests coverage

Duplicated Code [ Cut and paste ]

Comments

Architecture

Lack of Cohesion of MethodsCicular dependencies

Complexity

God classesGod methods

MCJUG 18 / 42

Page 46: Measure and Improve code quality.  Using automation

Lack of Cohesion of Methods [LCOM4]

MCJUG 19 / 42

Page 47: Measure and Improve code quality.  Using automation

Lack of Cohesion of Methods [LCOM4]

MCJUG 19 / 42

Page 48: Measure and Improve code quality.  Using automation

Code Complexity

MCJUG 20 / 42

Page 49: Measure and Improve code quality.  Using automation

Response for Class

MCJUG 21 / 42

Page 50: Measure and Improve code quality.  Using automation

Cyclomatic Complexity

Keywords that increment complexity:

if, for, while, case, catch, throw, return (that is

not the last statement of a method), conditionals,

else

Keywords that don’t increment complexity:

default, finally

MCJUG 22 / 42

Page 51: Measure and Improve code quality.  Using automation

Sonar

MCJUG 23 / 42

Page 52: Measure and Improve code quality.  Using automation

What is Sonar?

Web based tool.

Collects collects metrics from multiple projects

Repository of rules

Ticketing system for quality improvement

Dashboards / Reports

MCJUG 24 / 42

Page 53: Measure and Improve code quality.  Using automation

What is Sonar?

Web based tool.

Collects collects metrics from multiple projects

Repository of rules

Ticketing system for quality improvement

Dashboards / Reports

MCJUG 24 / 42

Page 54: Measure and Improve code quality.  Using automation

What is Sonar?

Web based tool.

Collects collects metrics from multiple projects

Repository of rules

Ticketing system for quality improvement

Dashboards / Reports

MCJUG 24 / 42

Page 55: Measure and Improve code quality.  Using automation

What is Sonar?

Web based tool.

Collects collects metrics from multiple projects

Repository of rules

Ticketing system for quality improvement

Dashboards / Reports

MCJUG 24 / 42

Page 56: Measure and Improve code quality.  Using automation

What is Sonar?

Web based tool.

Collects collects metrics from multiple projects

Repository of rules

Ticketing system for quality improvement

Dashboards / Reports

MCJUG 24 / 42

Page 57: Measure and Improve code quality.  Using automation

Why should I use sonar ?

Tester: Pinpoint the weak spots

Overly complex code

No coverage

MCJUG 25 / 42

Page 58: Measure and Improve code quality.  Using automation

Why should I use sonar ?

Developer: Education

Thread Safety

Resource management

Language subtleties

MCJUG 26 / 42

Page 59: Measure and Improve code quality.  Using automation

Why should I use sonar ?

Developer: Maintainability

Readability

Complexity

Missing or incorrect documentation

MCJUG 27 / 42

Page 60: Measure and Improve code quality.  Using automation

Why should I use sonar ?

Developer: Adherence to standards

Naming convention

Formatting

Use of bad methods System.out.println

Coding rule compliance

Boilerplate code

MCJUG 28 / 42

Page 61: Measure and Improve code quality.  Using automation

Why should I use sonar ?

Architect: Is design being degraded?

Circular dependencies

Lack of cohesion

Over complex classes and methods

MCJUG 29 / 42

Page 62: Measure and Improve code quality.  Using automation

Why should I use sonar ?

Big Boss

MCJUG 30 / 42

Page 63: Measure and Improve code quality.  Using automation

Why should I use sonar ?

Big Boss : Metrics

MCJUG 30 / 42

Page 64: Measure and Improve code quality.  Using automation

Platforms

Java

.NET

C++

Python

MCJUG 31 / 42

Page 65: Measure and Improve code quality.  Using automation

Platforms

Java

.NET

C++

Python

MCJUG 31 / 42

Page 66: Measure and Improve code quality.  Using automation

Platforms

Java

.NET

C++

Python

MCJUG 31 / 42

Page 67: Measure and Improve code quality.  Using automation

Platforms

Java

.NET

C++

Python

MCJUG 31 / 42

Page 68: Measure and Improve code quality.  Using automation

Demo

MCJUG 32 / 42

Page 69: Measure and Improve code quality.  Using automation

Main Dashboard

MCJUG 33 / 42

Page 70: Measure and Improve code quality.  Using automation

Project Drill-Down

MCJUG 34 / 42

Page 71: Measure and Improve code quality.  Using automation

Project Issues Drill-Down

MCJUG 35 / 42

Page 72: Measure and Improve code quality.  Using automation

Project Issues Drill-Down

MCJUG 35 / 42

Page 73: Measure and Improve code quality.  Using automation

Issue Tracking

MCJUG 36 / 42

Page 74: Measure and Improve code quality.  Using automation

Issue Tracking

MCJUG 36 / 42

Page 75: Measure and Improve code quality.  Using automation

Issue Tracking

MCJUG 36 / 42

Page 76: Measure and Improve code quality.  Using automation

Cut and Paste

MCJUG 37 / 42

Page 77: Measure and Improve code quality.  Using automation

Lack of Cohesion

MCJUG 38 / 42

Page 78: Measure and Improve code quality.  Using automation

Lack of Cohesion

MCJUG 38 / 42

Page 79: Measure and Improve code quality.  Using automation

Project Health

MCJUG 39 / 42

Page 80: Measure and Improve code quality.  Using automation

Project Health

MCJUG 39 / 42

Page 81: Measure and Improve code quality.  Using automation

Project Health

MCJUG 39 / 42

Page 82: Measure and Improve code quality.  Using automation

Project Health

MCJUG 39 / 42

Page 83: Measure and Improve code quality.  Using automation

Quality Profiles

MCJUG 40 / 42

Page 84: Measure and Improve code quality.  Using automation

Quality Profiles

MCJUG 40 / 42

Page 85: Measure and Improve code quality.  Using automation

Questions ???

MCJUG 41 / 42

Page 86: Measure and Improve code quality.  Using automation

End

MCJUG 42 / 42