SlideShare a Scribd company logo
Code quality

© 2012 Cognifide Limited. In commercial confidence only.
What is code quality
• Sample code quality questions:
− Are methods and classes clean, readable and short?
− Are connections between classes well-designed?
− Does your code follow Java conventions?


private static final rather than private final static

− Do you have unit tests? What is the coverage?
− Don’t you have some other code-smells?


Eg. if statement with too many || conditions

• Some issues caused by low quality code:
−
−
−
−

Problems with adding new features
Problems with collaboration
Hidden bugs
Hard to debug

• Static code analysis tools can check all things automatically
• Sonar – popular tool for Java

© 2012 Cognifide Limited. In commercial confidence only.
Coding standards

© 2012 Cognifide Limited. In commercial confidence only.
Coding standards – example
class FileUtils {
public final static String pngExtension = "png";
public static String getExtension(String filename) {
int DOTPos = filename.indexOf(".");
if (filename != null && DOTPos > -1) {
String extension = filename.substring(DOTPos+1);
return extension;
}
return null;
}
}

© 2012 Cognifide Limited. In commercial confidence only.
Cyclomatic complexity

© 2012 Cognifide Limited. In commercial confidence only.
Cyclomatic complexity
•
•
•
•
•

Basic code metric
Describes number of “branches” in method or class
Sequential code (no ifs, fors and whiles): complexity = 1
Each additional condition: +1
If method is too complex, we should split it into smaller ones

© 2012 Cognifide Limited. In commercial confidence only.
House of cards

© 2012 Cognifide Limited. In commercial confidence only.
House of cards

© 2012 Cognifide Limited. In commercial confidence only.
House of cards

© 2012 Cognifide Limited. In commercial confidence only.
Complexity for sequential code
byte[] buffer = new byte[1024];
InputStream stream = new FileInputStream("/my/file");
InputStream buffered = new BufferedInputStream(stream);
buffered.read(buffer);
buffered.close();

• Complexity: 1
• No conditions, simple flow

© 2012 Cognifide Limited. In commercial confidence only.
Complexity with one condition
byte[] buffer = new byte[1024];
File file = new File("/my/file");
if (!file.exists()) {
return;
}
InputStream stream = new FileInputStream(file);
InputStream buffered = new BufferedInputStream(stream);
buffered.read(buffer);
buffered.close();

• Complexity: 2

© 2012 Cognifide Limited. In commercial confidence only.
Complexity: formal definition
Formal definition: Edges – Nodes + 2 Components
for(int i=0;i<3;i++) {
System.out.println(i);
}

if(j == 42) {
System.out.println(”j is the answer”)
}
Edges: 9, Nodes: 8, Components: 1
E-N+2P=3

© 2012 Cognifide Limited. In commercial confidence only.
Class responsibilities

© 2012 Cognifide Limited. In commercial confidence only.
Single responsibility principle
• Each class should be responsible for only one thing
• Example: class Driver:
− 2 fields: car, brain,
− 5 methods: drive(), goTo(), stop(), getAngry(), drinkCoffee(),

• This class has 3 responsibilities:
− Driving car
− Getting angry
− Drinking coffe

• It should be split into 3 classes

© 2012 Cognifide Limited. In commercial confidence only.
LCOM4 & cohesion
• LCOM4 – Lack Of Cohesion Methods.
• How many responsibilities class?
• LCOM4 = 3 means that
− there are 3 not connected sets of methods/properties
− class can be split into three new classes.

• Class should be designed to have LCOM4 = 1
• Low LCOM4 = high cohesion
• Cohesion relates to coupling

© 2012 Cognifide Limited. In commercial confidence only.
Coupling

© 2012 Cognifide Limited. In commercial confidence only.
Tight coupling
• If a class (eg. Driver) invokes methods on some other class
(eg. Car) it’s tightly coupled with it
• In this case we can’t easily change Car implementation to
something other (eg. Tank)
• Real-life example: iPhone and its battery
public class Driver {
private final Car car;
public Driver(Car car) {
this.car = car;
}
public void driveCar() {
car.startEngine();
car.drive();
}

public class Car {
public void startEngine() {
…
}
public void drive() {
…
}
}

}
© 2012 Cognifide Limited. In commercial confidence only.
Loose coupling
• Class doesn’t need to know about other classes existence
• It only need to know about contracts (interfaces) provided by
other class
• Real-life example: screw and screwdriver
public class Driver {
private Vehicle vehicle;
public Driver(Vehicle vehicle) {
this.vehicle = vehicle;
}
public void drive() {
vehicle.startEngine();
vehicle.drive();
}

public interface Vehicle {
void startEngine();
void drive();
}
public class Car implements Vehicle {
public void startEngine() {
…
}
public void drive() {
…
}

}
}

© 2012 Cognifide Limited. In commercial confidence only.
Coupling & cohesion – summary
• Classes must be loosely coupled
and highly cohesive.
• Cohesion is the degree to which the
methods of a single class are tight
together.
− If class is not cohesive (eg. two methods
doesn’t share any property), it can be
split to two classes.

• Coupling is the degree to which each
class is tight to the others.
− Any change you make in one class has
impact to some other classes.
− Use interfaces & depdency injection

• Read more…
• Read even more…

© 2012 Cognifide Limited. In commercial confidence only.
Technical debt

© 2012 Cognifide Limited. In commercial confidence only.
Technical debt
• „Doing things the quick and dirty way sets us up with a
technical debt, which is similar to a financial debt.”
• Metric based on:
−
−
−
−
−

•
•
•
•

duplications,
violations,
(lack of) comments,
coverage,
complexity.

Absolute debt in mandays and cash
Debt ratio – dependent on the project size.
Useful for project manager
Read more...

© 2012 Cognifide Limited. In commercial confidence only.
Other metrics

© 2012 Cognifide Limited. In commercial confidence only.
Other code metrics
•
•
•
•
•

Lines of code
Unit test coverage
Responses for class
…
All these metrics can be checked via Sonar
− Free & very useful software
− Can be integrated with Eclipse

• Visual Studio provides integrated metrics as well

© 2012 Cognifide Limited. In commercial confidence only.

More Related Content

What's hot

DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...
DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...
DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...
DevLabs Alliance
 
Vb net xp_04
Vb net xp_04Vb net xp_04
Vb net xp_04
Niit Care
 
Review Session and Attending Java Interviews
Review Session and Attending Java InterviewsReview Session and Attending Java Interviews
Review Session and Attending Java Interviews
RatnaJava
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdet
DevLabs Alliance
 
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesOOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and Interfaces
Hitesh-Java
 
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaTop 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Edureka!
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
Ye Win
 
3. C# Guide Advance - To Print
3. C# Guide Advance - To Print3. C# Guide Advance - To Print
3. C# Guide Advance - To Print
Chinthaka Fernando
 
Top 20 cucumber interview questions for sdet
Top 20 cucumber interview questions for sdetTop 20 cucumber interview questions for sdet
Top 20 cucumber interview questions for sdet
DevLabs Alliance
 
OOP in Java
OOP in JavaOOP in Java
OOP in Java
wiradikusuma
 
Java interview question
Java interview questionJava interview question
Java interview question
varatharajanrajeswar
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
Ehtisham Ali
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiers
Khaled Adnan
 
C# Interview Questions | Edureka
C# Interview Questions | EdurekaC# Interview Questions | Edureka
C# Interview Questions | Edureka
Edureka!
 

What's hot (14)

DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...
DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...
DevLabs Alliance Top 20 Software Testing Interview Questions for SDET - by De...
 
Vb net xp_04
Vb net xp_04Vb net xp_04
Vb net xp_04
 
Review Session and Attending Java Interviews
Review Session and Attending Java InterviewsReview Session and Attending Java Interviews
Review Session and Attending Java Interviews
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdet
 
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesOOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and Interfaces
 
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaTop 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | Edureka
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
3. C# Guide Advance - To Print
3. C# Guide Advance - To Print3. C# Guide Advance - To Print
3. C# Guide Advance - To Print
 
Top 20 cucumber interview questions for sdet
Top 20 cucumber interview questions for sdetTop 20 cucumber interview questions for sdet
Top 20 cucumber interview questions for sdet
 
OOP in Java
OOP in JavaOOP in Java
OOP in Java
 
Java interview question
Java interview questionJava interview question
Java interview question
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiers
 
C# Interview Questions | Edureka
C# Interview Questions | EdurekaC# Interview Questions | Edureka
C# Interview Questions | Edureka
 

Viewers also liked

Project quality (and test process) metrics
Project quality (and test process) metricsProject quality (and test process) metrics
Project quality (and test process) metrics
Zbyszek Mockun
 
Test Metrics and KPIs
Test Metrics and KPIsTest Metrics and KPIs
Test Metrics and KPIs
Devendra Singh
 
SlingQuery
SlingQuerySlingQuery
SlingQuery
Tomasz Rękawek
 
CRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migrationCRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migration
Tomasz Rękawek
 
Agile Scrum in 60 minutes
Agile Scrum in 60 minutesAgile Scrum in 60 minutes
Agile Scrum in 60 minutes
Syed Arh
 
Agile metrics - Measure and Improve
Agile metrics - Measure and ImproveAgile metrics - Measure and Improve
Agile metrics - Measure and Improve
WemanityUK
 
Agile Metrics
Agile MetricsAgile Metrics
Agile Metrics
Mikalai Alimenkou
 
Agile Metrics
Agile MetricsAgile Metrics
Agile Metrics
Andrzej Wiech
 
Top 10 Agile Metrics
Top 10 Agile MetricsTop 10 Agile Metrics
Top 10 Agile Metrics
XBOSoft
 
Presentation -Quality Metrics For Agile Development
Presentation -Quality Metrics For Agile DevelopmentPresentation -Quality Metrics For Agile Development
Presentation -Quality Metrics For Agile Development
Nabilahmed Patel
 
Agile Base Camp - Agile metrics
Agile Base Camp - Agile metricsAgile Base Camp - Agile metrics
Agile Base Camp - Agile metrics
Serge Kovaleff
 
Measuring the Code Quality Using Software Metrics
Measuring the Code Quality Using Software MetricsMeasuring the Code Quality Using Software Metrics
Measuring the Code Quality Using Software Metrics
Geetha Anjali
 
Agile Testing - presentation for Agile User Group
Agile Testing - presentation for Agile User GroupAgile Testing - presentation for Agile User Group
Agile Testing - presentation for Agile User Group
suwalki24.pl
 
Agile code quality metrics
Agile code quality metricsAgile code quality metrics
Agile code quality metrics
Gil Nahmias
 
Agile Metrics : A seminal approach for calculating Metrics in Agile Projects
Agile Metrics : A seminal approach for calculating Metrics in Agile ProjectsAgile Metrics : A seminal approach for calculating Metrics in Agile Projects
Agile Metrics : A seminal approach for calculating Metrics in Agile Projects
Prashant Ram
 
Agile Metrics That Matter
Agile Metrics That MatterAgile Metrics That Matter
Agile Metrics That Matter
ThoughtWorks Studios
 
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
VersionOne
 

Viewers also liked (17)

Project quality (and test process) metrics
Project quality (and test process) metricsProject quality (and test process) metrics
Project quality (and test process) metrics
 
Test Metrics and KPIs
Test Metrics and KPIsTest Metrics and KPIs
Test Metrics and KPIs
 
SlingQuery
SlingQuerySlingQuery
SlingQuery
 
CRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migrationCRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migration
 
Agile Scrum in 60 minutes
Agile Scrum in 60 minutesAgile Scrum in 60 minutes
Agile Scrum in 60 minutes
 
Agile metrics - Measure and Improve
Agile metrics - Measure and ImproveAgile metrics - Measure and Improve
Agile metrics - Measure and Improve
 
Agile Metrics
Agile MetricsAgile Metrics
Agile Metrics
 
Agile Metrics
Agile MetricsAgile Metrics
Agile Metrics
 
Top 10 Agile Metrics
Top 10 Agile MetricsTop 10 Agile Metrics
Top 10 Agile Metrics
 
Presentation -Quality Metrics For Agile Development
Presentation -Quality Metrics For Agile DevelopmentPresentation -Quality Metrics For Agile Development
Presentation -Quality Metrics For Agile Development
 
Agile Base Camp - Agile metrics
Agile Base Camp - Agile metricsAgile Base Camp - Agile metrics
Agile Base Camp - Agile metrics
 
Measuring the Code Quality Using Software Metrics
Measuring the Code Quality Using Software MetricsMeasuring the Code Quality Using Software Metrics
Measuring the Code Quality Using Software Metrics
 
Agile Testing - presentation for Agile User Group
Agile Testing - presentation for Agile User GroupAgile Testing - presentation for Agile User Group
Agile Testing - presentation for Agile User Group
 
Agile code quality metrics
Agile code quality metricsAgile code quality metrics
Agile code quality metrics
 
Agile Metrics : A seminal approach for calculating Metrics in Agile Projects
Agile Metrics : A seminal approach for calculating Metrics in Agile ProjectsAgile Metrics : A seminal approach for calculating Metrics in Agile Projects
Agile Metrics : A seminal approach for calculating Metrics in Agile Projects
 
Agile Metrics That Matter
Agile Metrics That MatterAgile Metrics That Matter
Agile Metrics That Matter
 
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
 

Similar to Code metrics

SPCA2013 - Building a SharePoint Factory
SPCA2013 - Building a SharePoint FactorySPCA2013 - Building a SharePoint Factory
SPCA2013 - Building a SharePoint Factory
NCCOMMS
 
Integration testing - A&BP CC
Integration testing - A&BP CCIntegration testing - A&BP CC
Integration testing - A&BP CC
JWORKS powered by Ordina
 
Approaching ATDD/BDD
Approaching ATDD/BDDApproaching ATDD/BDD
Approaching ATDD/BDD
Dhaval Dalal
 
Seven elements of technical Agility - Gil Broza - Agile Israel 2013
Seven elements of technical Agility - Gil Broza - Agile Israel 2013Seven elements of technical Agility - Gil Broza - Agile Israel 2013
Seven elements of technical Agility - Gil Broza - Agile Israel 2013
AgileSparks
 
Project Work
Project WorkProject Work
Project Work
z02247
 
Edge Presentation Ppt
Edge Presentation PptEdge Presentation Ppt
Edge Presentation Ppt
BrendaDean
 
DS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham ChartersDS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham Charters
mfrancis
 
Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injection
Neoito
 
DS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham ChartersDS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham Charters
mfrancis
 
Our research lines on Model-Driven Engineering and Software Engineering
Our research lines on Model-Driven Engineering and Software EngineeringOur research lines on Model-Driven Engineering and Software Engineering
Our research lines on Model-Driven Engineering and Software Engineering
Jordi Cabot
 
Framework for Web Automation Testing
Framework for Web Automation TestingFramework for Web Automation Testing
Framework for Web Automation Testing
Taras Lytvyn
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
Sam Nasr, MCSA, MVP
 
Integrating DDS into AXCIOMA - The Component Approach
Integrating DDS into AXCIOMA - The Component ApproachIntegrating DDS into AXCIOMA - The Component Approach
Integrating DDS into AXCIOMA - The Component Approach
Real-Time Innovations (RTI)
 
Integrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approachIntegrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approach
Remedy IT
 
Software quality - no more bugs!
Software quality - no more bugs!Software quality - no more bugs!
Software quality - no more bugs!
Arnon Axelrod
 
Common Design Patterns.pptx
Common Design Patterns.pptxCommon Design Patterns.pptx
Common Design Patterns.pptx
fake195786
 
Ravindra Prasad
Ravindra PrasadRavindra Prasad
Ravindra Prasad
Ravindra Prasad
 
Mobile Code Optimisation Services
Mobile Code Optimisation ServicesMobile Code Optimisation Services
Mobile Code Optimisation Services
Raja Nagendra Kumar
 
Binary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code TestingBinary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code Testing
Binary Studio
 
Ada 2012
Ada 2012Ada 2012
Ada 2012
AdaCore
 

Similar to Code metrics (20)

SPCA2013 - Building a SharePoint Factory
SPCA2013 - Building a SharePoint FactorySPCA2013 - Building a SharePoint Factory
SPCA2013 - Building a SharePoint Factory
 
Integration testing - A&BP CC
Integration testing - A&BP CCIntegration testing - A&BP CC
Integration testing - A&BP CC
 
Approaching ATDD/BDD
Approaching ATDD/BDDApproaching ATDD/BDD
Approaching ATDD/BDD
 
Seven elements of technical Agility - Gil Broza - Agile Israel 2013
Seven elements of technical Agility - Gil Broza - Agile Israel 2013Seven elements of technical Agility - Gil Broza - Agile Israel 2013
Seven elements of technical Agility - Gil Broza - Agile Israel 2013
 
Project Work
Project WorkProject Work
Project Work
 
Edge Presentation Ppt
Edge Presentation PptEdge Presentation Ppt
Edge Presentation Ppt
 
DS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham ChartersDS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham Charters
 
Neoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injectionNeoito — Design patterns and depenedency injection
Neoito — Design patterns and depenedency injection
 
DS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham ChartersDS, BP, EJB, CDI, WTF!? - Graham Charters
DS, BP, EJB, CDI, WTF!? - Graham Charters
 
Our research lines on Model-Driven Engineering and Software Engineering
Our research lines on Model-Driven Engineering and Software EngineeringOur research lines on Model-Driven Engineering and Software Engineering
Our research lines on Model-Driven Engineering and Software Engineering
 
Framework for Web Automation Testing
Framework for Web Automation TestingFramework for Web Automation Testing
Framework for Web Automation Testing
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Integrating DDS into AXCIOMA - The Component Approach
Integrating DDS into AXCIOMA - The Component ApproachIntegrating DDS into AXCIOMA - The Component Approach
Integrating DDS into AXCIOMA - The Component Approach
 
Integrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approachIntegrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approach
 
Software quality - no more bugs!
Software quality - no more bugs!Software quality - no more bugs!
Software quality - no more bugs!
 
Common Design Patterns.pptx
Common Design Patterns.pptxCommon Design Patterns.pptx
Common Design Patterns.pptx
 
Ravindra Prasad
Ravindra PrasadRavindra Prasad
Ravindra Prasad
 
Mobile Code Optimisation Services
Mobile Code Optimisation ServicesMobile Code Optimisation Services
Mobile Code Optimisation Services
 
Binary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code TestingBinary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code Testing
 
Ada 2012
Ada 2012Ada 2012
Ada 2012
 

More from Tomasz Rękawek

Radio ad blocker
Radio ad blockerRadio ad blocker
Radio ad blocker
Tomasz Rękawek
 
Deep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on KubernetesDeep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on Kubernetes
Tomasz Rękawek
 
Emulating Game Boy in Java
Emulating Game Boy in JavaEmulating Game Boy in Java
Emulating Game Boy in Java
Tomasz Rękawek
 
Zero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using DockerZero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using Docker
Tomasz Rękawek
 
Inter-Sling communication with message queue
Inter-Sling communication with message queueInter-Sling communication with message queue
Inter-Sling communication with message queue
Tomasz Rękawek
 
Sling Dynamic Include
Sling Dynamic IncludeSling Dynamic Include
Sling Dynamic Include
Tomasz Rękawek
 
Shooting rabbits with sling
Shooting rabbits with slingShooting rabbits with sling
Shooting rabbits with sling
Tomasz Rękawek
 

More from Tomasz Rękawek (7)

Radio ad blocker
Radio ad blockerRadio ad blocker
Radio ad blocker
 
Deep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on KubernetesDeep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on Kubernetes
 
Emulating Game Boy in Java
Emulating Game Boy in JavaEmulating Game Boy in Java
Emulating Game Boy in Java
 
Zero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using DockerZero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using Docker
 
Inter-Sling communication with message queue
Inter-Sling communication with message queueInter-Sling communication with message queue
Inter-Sling communication with message queue
 
Sling Dynamic Include
Sling Dynamic IncludeSling Dynamic Include
Sling Dynamic Include
 
Shooting rabbits with sling
Shooting rabbits with slingShooting rabbits with sling
Shooting rabbits with sling
 

Recently uploaded

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 

Recently uploaded (20)

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 

Code metrics

  • 1. Code quality © 2012 Cognifide Limited. In commercial confidence only.
  • 2. What is code quality • Sample code quality questions: − Are methods and classes clean, readable and short? − Are connections between classes well-designed? − Does your code follow Java conventions?  private static final rather than private final static − Do you have unit tests? What is the coverage? − Don’t you have some other code-smells?  Eg. if statement with too many || conditions • Some issues caused by low quality code: − − − − Problems with adding new features Problems with collaboration Hidden bugs Hard to debug • Static code analysis tools can check all things automatically • Sonar – popular tool for Java © 2012 Cognifide Limited. In commercial confidence only.
  • 3. Coding standards © 2012 Cognifide Limited. In commercial confidence only.
  • 4. Coding standards – example class FileUtils { public final static String pngExtension = "png"; public static String getExtension(String filename) { int DOTPos = filename.indexOf("."); if (filename != null && DOTPos > -1) { String extension = filename.substring(DOTPos+1); return extension; } return null; } } © 2012 Cognifide Limited. In commercial confidence only.
  • 5. Cyclomatic complexity © 2012 Cognifide Limited. In commercial confidence only.
  • 6. Cyclomatic complexity • • • • • Basic code metric Describes number of “branches” in method or class Sequential code (no ifs, fors and whiles): complexity = 1 Each additional condition: +1 If method is too complex, we should split it into smaller ones © 2012 Cognifide Limited. In commercial confidence only.
  • 7. House of cards © 2012 Cognifide Limited. In commercial confidence only.
  • 8. House of cards © 2012 Cognifide Limited. In commercial confidence only.
  • 9. House of cards © 2012 Cognifide Limited. In commercial confidence only.
  • 10. Complexity for sequential code byte[] buffer = new byte[1024]; InputStream stream = new FileInputStream("/my/file"); InputStream buffered = new BufferedInputStream(stream); buffered.read(buffer); buffered.close(); • Complexity: 1 • No conditions, simple flow © 2012 Cognifide Limited. In commercial confidence only.
  • 11. Complexity with one condition byte[] buffer = new byte[1024]; File file = new File("/my/file"); if (!file.exists()) { return; } InputStream stream = new FileInputStream(file); InputStream buffered = new BufferedInputStream(stream); buffered.read(buffer); buffered.close(); • Complexity: 2 © 2012 Cognifide Limited. In commercial confidence only.
  • 12. Complexity: formal definition Formal definition: Edges – Nodes + 2 Components for(int i=0;i<3;i++) { System.out.println(i); } if(j == 42) { System.out.println(”j is the answer”) } Edges: 9, Nodes: 8, Components: 1 E-N+2P=3 © 2012 Cognifide Limited. In commercial confidence only.
  • 13. Class responsibilities © 2012 Cognifide Limited. In commercial confidence only.
  • 14. Single responsibility principle • Each class should be responsible for only one thing • Example: class Driver: − 2 fields: car, brain, − 5 methods: drive(), goTo(), stop(), getAngry(), drinkCoffee(), • This class has 3 responsibilities: − Driving car − Getting angry − Drinking coffe • It should be split into 3 classes © 2012 Cognifide Limited. In commercial confidence only.
  • 15. LCOM4 & cohesion • LCOM4 – Lack Of Cohesion Methods. • How many responsibilities class? • LCOM4 = 3 means that − there are 3 not connected sets of methods/properties − class can be split into three new classes. • Class should be designed to have LCOM4 = 1 • Low LCOM4 = high cohesion • Cohesion relates to coupling © 2012 Cognifide Limited. In commercial confidence only.
  • 16. Coupling © 2012 Cognifide Limited. In commercial confidence only.
  • 17. Tight coupling • If a class (eg. Driver) invokes methods on some other class (eg. Car) it’s tightly coupled with it • In this case we can’t easily change Car implementation to something other (eg. Tank) • Real-life example: iPhone and its battery public class Driver { private final Car car; public Driver(Car car) { this.car = car; } public void driveCar() { car.startEngine(); car.drive(); } public class Car { public void startEngine() { … } public void drive() { … } } } © 2012 Cognifide Limited. In commercial confidence only.
  • 18. Loose coupling • Class doesn’t need to know about other classes existence • It only need to know about contracts (interfaces) provided by other class • Real-life example: screw and screwdriver public class Driver { private Vehicle vehicle; public Driver(Vehicle vehicle) { this.vehicle = vehicle; } public void drive() { vehicle.startEngine(); vehicle.drive(); } public interface Vehicle { void startEngine(); void drive(); } public class Car implements Vehicle { public void startEngine() { … } public void drive() { … } } } © 2012 Cognifide Limited. In commercial confidence only.
  • 19. Coupling & cohesion – summary • Classes must be loosely coupled and highly cohesive. • Cohesion is the degree to which the methods of a single class are tight together. − If class is not cohesive (eg. two methods doesn’t share any property), it can be split to two classes. • Coupling is the degree to which each class is tight to the others. − Any change you make in one class has impact to some other classes. − Use interfaces & depdency injection • Read more… • Read even more… © 2012 Cognifide Limited. In commercial confidence only.
  • 20. Technical debt © 2012 Cognifide Limited. In commercial confidence only.
  • 21. Technical debt • „Doing things the quick and dirty way sets us up with a technical debt, which is similar to a financial debt.” • Metric based on: − − − − − • • • • duplications, violations, (lack of) comments, coverage, complexity. Absolute debt in mandays and cash Debt ratio – dependent on the project size. Useful for project manager Read more... © 2012 Cognifide Limited. In commercial confidence only.
  • 22. Other metrics © 2012 Cognifide Limited. In commercial confidence only.
  • 23. Other code metrics • • • • • Lines of code Unit test coverage Responses for class … All these metrics can be checked via Sonar − Free & very useful software − Can be integrated with Eclipse • Visual Studio provides integrated metrics as well © 2012 Cognifide Limited. In commercial confidence only.