measure and improve code quality. using automation
DESCRIPTION
Slides from my talk given at MCJUG on 9/17/2014 on measuring and improving code quality using tools such as Sonar.TRANSCRIPT
Measure and improvecode quality
Using automation
About myself
MCJUG 2 / 42
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
What is Code Quality?
MCJUG 4 / 42
What is Quality?
MCJUG 5 / 42
David Garvin
Five Dimensions of Quality
1 Transcendental
2 Product
3 User
4 Manufacturing
5 Value
MCJUG 6 / 42
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
Transcendental
Aristotle
Quality is not an act, but a habit.
MCJUG 7 / 42
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
Transcendental
Pirsig
No way to explain, but everybody knows it through repeatedexposure to low / high quality product
MCJUG 7 / 42
Product: Precise measurement of known variable
Ice Cream
More butterfat → higher quiality
MCJUG 8 / 42
Product: Precise measurement of known variable
Persian rugs
More knots per square inch → higher quiality
MCJUG 8 / 42
User
More desirable products are of higher quality.
MCJUG 9 / 42
User
Better selling products are of higher quality.
MCJUG 9 / 42
Manufacturing
Conformance to well defined standard.
MCJUG 10 / 42
Manufacturing
Lower variance → higher quality.
MCJUG 10 / 42
Value : Monetary
More expensive products are of higher quality.
MCJUG 11 / 42
Value : Monetary
Ferrari is of higher quality than Pinto.
MCJUG 11 / 42
What is Code Quality?
MCJUG 12 / 42
Code Quality
External
Internal
MCJUG 13 / 42
External Code Quality
MCJUG 14 / 42
External Code Quality
MCJUG 14 / 42
External Code Quality
MCJUG 14 / 42
External Code Quality
MCJUG 14 / 42
External Code Quality
MCJUG 14 / 42
External Code Quality
MCJUG 14 / 42
External Code Quality
MCJUG 14 / 42
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
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
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
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
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
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
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
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
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
Internal Code Quality
How do we measure it?
What’s our equivalent of plywood?
MCJUG 17 / 42
Internal Code Quality
How do we measure it?
What’s our equivalent of plywood?
MCJUG 17 / 42
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
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
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
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
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
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
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
Lack of Cohesion of Methods [LCOM4]
MCJUG 19 / 42
Lack of Cohesion of Methods [LCOM4]
MCJUG 19 / 42
Code Complexity
MCJUG 20 / 42
Response for Class
MCJUG 21 / 42
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
Sonar
MCJUG 23 / 42
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
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
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
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
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
Why should I use sonar ?
Tester: Pinpoint the weak spots
Overly complex code
No coverage
MCJUG 25 / 42
Why should I use sonar ?
Developer: Education
Thread Safety
Resource management
Language subtleties
MCJUG 26 / 42
Why should I use sonar ?
Developer: Maintainability
Readability
Complexity
Missing or incorrect documentation
MCJUG 27 / 42
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
Why should I use sonar ?
Architect: Is design being degraded?
Circular dependencies
Lack of cohesion
Over complex classes and methods
MCJUG 29 / 42
Why should I use sonar ?
Big Boss
MCJUG 30 / 42
Why should I use sonar ?
Big Boss : Metrics
MCJUG 30 / 42
Platforms
Java
.NET
C++
Python
MCJUG 31 / 42
Platforms
Java
.NET
C++
Python
MCJUG 31 / 42
Platforms
Java
.NET
C++
Python
MCJUG 31 / 42
Platforms
Java
.NET
C++
Python
MCJUG 31 / 42
Demo
MCJUG 32 / 42
Main Dashboard
MCJUG 33 / 42
Project Drill-Down
MCJUG 34 / 42
Project Issues Drill-Down
MCJUG 35 / 42
Project Issues Drill-Down
MCJUG 35 / 42
Issue Tracking
MCJUG 36 / 42
Issue Tracking
MCJUG 36 / 42
Issue Tracking
MCJUG 36 / 42
Cut and Paste
MCJUG 37 / 42
Lack of Cohesion
MCJUG 38 / 42
Lack of Cohesion
MCJUG 38 / 42
Project Health
MCJUG 39 / 42
Project Health
MCJUG 39 / 42
Project Health
MCJUG 39 / 42
Project Health
MCJUG 39 / 42
Quality Profiles
MCJUG 40 / 42
Quality Profiles
MCJUG 40 / 42
Questions ???
MCJUG 41 / 42
End
MCJUG 42 / 42