SlideShare uma empresa Scribd logo
1 de 38
1Caring About Code Quality
Caring About Code
Quality
EL MAHDI BENZEKRI | elmahdi.benzekri@gmail.com
2019
2Caring About Code Quality
Clean Code: A Handbook of Agile Software Craftsmanship
by Robert C. Martin
The Book
3Caring About Code Quality
Does it work?
What is Clean Code?
Does it scale?
Is it esthetic?
Is it maintainable?
Is it testable?
Is it short?
Is it clever?
Does it have explanatory
comments?
Is it easy to
understand?
Is it well-structured?
Is it object-oriented?
4Caring About Code Quality
• Focused
• Single-minded attitude
• Undistracted and unpolluted
• Readable, simple and direct
• Compact and literate
• Contains only what is necessary
• Makes it easy for other developers to enhance it
• Tests should be also clean
• Looks like it’s author cares
• FoContains no duplicates
• undations are established on tiny abstractions
What is Clean Code after all?
5Caring About Code Quality
• Subjective
• If you can’t measure, you can’t improve
• Identify what matters
• Defend and justify decisions.
The need for measurement
6Caring About Code Quality
Cyclomatic complexity
public void foo() {
if (c1) {
f1();
} else {
f2();
}
if (c2) {
f3();
} else {
f4();
}
}
• Upper bound for the number of test cases
that are necessary to achieve a complete
branch coverage
• Lower bound for the number of paths
through the control flow graph
• Desirable value: below 10
Cyclomatic complexity: 3
7Caring About Code Quality
Always leave the campground
cleaner than you found it.
The Boy Scout Rule
8Caring About Code Quality
• Came from city crime researchers
• A broken window will trigger a building into a
smashed and abandoned derelict
• So does the software
Broken Window Theory
9Caring About Code Quality
Composed method example
public void add(Object element) {
if (!readOnly) {
int newSize = size + 1;
if (newSize > elements.length) {
Object[] newElements = new Object[elements.length + 10];
for (int index = 0; index < size; index++) {
newElements[index] = elements[index];
elements = newElements;
}
}
elements[size++] = element;
}
}
10Caring About Code Quality
Implementation patterns
11Caring About Code Quality
Composed method example
public void add(Object element) {
if (!isReadOnly()) {
if (atCapacity()) {
grow();
}
addElement(element);
}
}
12Caring About Code Quality
• Instant feedback
• Allows you to make changes to code quickly
• Help you understand the design of the code you
are working on
• Writing testable code helps to achieve better
code quality
• Unit tests are a form of sample code
• Test-first forces you to plan before you code
Advantages of Unit tests
13Caring About Code Quality
• Whether the unit you're testing should be
isolated from its collaborators
• Mockist approach
– Isolate from dependencies
– More flexible in what you can test
• Classic approach
– No attempt to isolate unless communicating
with the collaborator is awkward
– Less brittle tests
Unit tests collaborator isolation
14Caring About Code Quality
• Change Risk Analysis and Prediction
• Help you identify code that might be particularly difficult to
understand, test, or maintain
• 𝐶𝑅𝐴𝑃 𝑚 = cycl_comp(m)2
∗ 1 − 𝑐𝑜𝑣𝑒𝑟𝑎𝑔𝑒
3
+ cycl_comp(m)
• A method with a CRAP score over 30 is considered
unacceptable
C.R.A.P. metric
Cyclomatic
Complexity
Coverage
required
0 – 5 0%
10 42%
15 57%
20 71%
25 80%
30 100%
31+ Not possible
15Caring About Code Quality
• Don’t build complex machines
• Don’t build frameworks
• Make the software so simple that there are
obviously no deficiencies
• Keep it simple, stupid (KISS)
Rube Goldberg Machines
16Caring About Code Quality
• Avoid Cargo cult programming
• Question authority
• Accept feedback and give feedback
Angry monkeys experiment
17Caring About Code Quality
DESIGN PATTERNS IN
PRACTICE
2019
18Caring About Code Quality
Transfer object pattern
19Caring About Code Quality
Front controller
20Caring About Code Quality
Chain of responsibility
21Caring About Code Quality
Proxy pattern
22Caring About Code Quality
• Thread safety
• Valid state
• Encapsulation
• Simpler to test
• More readable and maintainable code
Immutable Object
23Caring About Code Quality
Null Object
24Caring About Code Quality
Flyweight pattern
25Caring About Code Quality
Template method
26Caring About Code Quality
• State Pattern’s intent is to manage states of the object along with object’s behavior which changes
with its state.
• State typically involves a getStatus method and a reference back to the context
• state, behavior is autodeterminated, strategy, behavior is determinated by caller.
• Strategy Pattern is to have a family of interchangeable algorithms
• Relation between individual states/individual strategies
State vs Strategy
27Caring About Code Quality
Observer Pattern
28Caring About Code Quality
Facade Pattern
29Caring About Code Quality
Decorator Pattern
30Caring About Code Quality
THINKING
AND
CODING EFFICIENTLY
31Caring About Code Quality
Effective Java
• Level of access ? Minimum
• Classpath ?
• Composition vs inheritance
• Avoid side effects
• Minimize Mutability
• Check methods/constructosr parameters for validity
• Always override hashCode when you override equals
• …
• https://github.com/HugoMatilla/Effective-JAVA-Summary
32Caring About Code Quality
• “This” keyword
• Chained
• Popular java Fluent API’s:
– Java Object Oriented Querying (jOOQ) API
– Java 8’s Date Time API
– Java 9’s Money and Currency API
Fluent API
33Caring About Code Quality
• Handle UI interractions
GRASP - The Controller
34Caring About Code Quality
• Information expert
• Encapsulating information
GRASP - The Expert
35Caring About Code Quality
• Creation responsibility
• Have enough information to instantiate an object
GRASP - The Creator
36Caring About Code Quality
• it is a measure of how strongly related each
piece of functionality expressed by
the source code of a software module is.
GRASP - High cohesion
37Caring About Code Quality
• The smallest number of references
between objects as possible
• Reason of change
GRASP - Low coupling
38Caring About Code Quality
EMBZENZEKRI@SQLI.COM
THANK YOU FOR ATTENTION!
QUESTIONS?

Mais conteúdo relacionado

Mais procurados

Adopting Agile
Adopting AgileAdopting Agile
Adopting AgileCoverity
 
Git branching policy and review comment's prefix
Git branching policy and review comment's prefixGit branching policy and review comment's prefix
Git branching policy and review comment's prefixKumaresh Chandra Baruri
 
Source code comprehension on evolving software
Source code comprehension on evolving softwareSource code comprehension on evolving software
Source code comprehension on evolving softwareSung Kim
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012cobyst
 
Code review
Code reviewCode review
Code reviewdqpi
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applicationsnadeembtech
 
Design for Testability in Practice
Design for Testability in PracticeDesign for Testability in Practice
Design for Testability in PracticeTechWell
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeyCefalo
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDDArati Joshi
 
Code quality
Code qualityCode quality
Code qualityProvectus
 
Software testing
Software testingSoftware testing
Software testingthaneofife
 
Practical pointers for better code review
Practical pointers for better code reviewPractical pointers for better code review
Practical pointers for better code reviewkhink
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...AgileNetwork
 

Mais procurados (20)

Adopting Agile
Adopting AgileAdopting Agile
Adopting Agile
 
Git branching policy and review comment's prefix
Git branching policy and review comment's prefixGit branching policy and review comment's prefix
Git branching policy and review comment's prefix
 
Clean code
Clean codeClean code
Clean code
 
Source code comprehension on evolving software
Source code comprehension on evolving softwareSource code comprehension on evolving software
Source code comprehension on evolving software
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
 
Code review
Code reviewCode review
Code review
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applications
 
Code Review
Code ReviewCode Review
Code Review
 
Design for Testability in Practice
Design for Testability in PracticeDesign for Testability in Practice
Design for Testability in Practice
 
Bdd with m spec
Bdd with m specBdd with m spec
Bdd with m spec
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
Sqa
Sqa Sqa
Sqa
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Code quality
Code qualityCode quality
Code quality
 
Software testing
Software testingSoftware testing
Software testing
 
Practical pointers for better code review
Practical pointers for better code reviewPractical pointers for better code review
Practical pointers for better code review
 
Clean code coding like a professional
Clean code   coding like a professionalClean code   coding like a professional
Clean code coding like a professional
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 

Semelhante a Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)

Code qualityCode qualityCode quality.pptx
Code qualityCode qualityCode quality.pptxCode qualityCode qualityCode quality.pptx
Code qualityCode qualityCode quality.pptxSanjarMadraximov
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code ReviewMilan Vukoje
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit TestingShaun Abram
 
Software Quality without Testing
Software Quality without TestingSoftware Quality without Testing
Software Quality without TestingNagarro
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)lqi
 
CodeMR - Software Quality
CodeMR - Software QualityCodeMR - Software Quality
CodeMR - Software QualityCodeMR
 
Code Review Tool Evaluation
Code Review Tool EvaluationCode Review Tool Evaluation
Code Review Tool EvaluationKate Semizhon
 
The Dark Side of Code Metrics
The Dark Side of Code MetricsThe Dark Side of Code Metrics
The Dark Side of Code MetricsDonald Belcham
 
Developing a Culture of Quality Code at Givelify (Tech Talk)
Developing a Culture of Quality Code at Givelify (Tech Talk)Developing a Culture of Quality Code at Givelify (Tech Talk)
Developing a Culture of Quality Code at Givelify (Tech Talk)Scott Keck-Warren
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile DeveloperBSGAfrica
 
Software Testing Basics
Software Testing BasicsSoftware Testing Basics
Software Testing BasicsBelal Raslan
 
caring_about_code_quality
caring_about_code_qualitycaring_about_code_quality
caring_about_code_qualityKetan Patel
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptxAmalEldhose2
 
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptxcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptxsarah david
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Theo Jungeblut
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipTheo Jungeblut
 
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdfcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdfsarah david
 

Semelhante a Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern) (20)

clean code - uncle bob
clean code - uncle bobclean code - uncle bob
clean code - uncle bob
 
Code qualityCode qualityCode quality.pptx
Code qualityCode qualityCode quality.pptxCode qualityCode qualityCode quality.pptx
Code qualityCode qualityCode quality.pptx
 
Code Reviews
Code ReviewsCode Reviews
Code Reviews
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
Software Quality without Testing
Software Quality without TestingSoftware Quality without Testing
Software Quality without Testing
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)
 
CodeMR - Software Quality
CodeMR - Software QualityCodeMR - Software Quality
CodeMR - Software Quality
 
Code Review Tool Evaluation
Code Review Tool EvaluationCode Review Tool Evaluation
Code Review Tool Evaluation
 
The Dark Side of Code Metrics
The Dark Side of Code MetricsThe Dark Side of Code Metrics
The Dark Side of Code Metrics
 
Developing a Culture of Quality Code at Givelify (Tech Talk)
Developing a Culture of Quality Code at Givelify (Tech Talk)Developing a Culture of Quality Code at Givelify (Tech Talk)
Developing a Culture of Quality Code at Givelify (Tech Talk)
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile Developer
 
Software Testing Basics
Software Testing BasicsSoftware Testing Basics
Software Testing Basics
 
caring_about_code_quality
caring_about_code_qualitycaring_about_code_quality
caring_about_code_quality
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptxcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
 
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdfcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
 

Último

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Último (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)

  • 1. 1Caring About Code Quality Caring About Code Quality EL MAHDI BENZEKRI | elmahdi.benzekri@gmail.com 2019
  • 2. 2Caring About Code Quality Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin The Book
  • 3. 3Caring About Code Quality Does it work? What is Clean Code? Does it scale? Is it esthetic? Is it maintainable? Is it testable? Is it short? Is it clever? Does it have explanatory comments? Is it easy to understand? Is it well-structured? Is it object-oriented?
  • 4. 4Caring About Code Quality • Focused • Single-minded attitude • Undistracted and unpolluted • Readable, simple and direct • Compact and literate • Contains only what is necessary • Makes it easy for other developers to enhance it • Tests should be also clean • Looks like it’s author cares • FoContains no duplicates • undations are established on tiny abstractions What is Clean Code after all?
  • 5. 5Caring About Code Quality • Subjective • If you can’t measure, you can’t improve • Identify what matters • Defend and justify decisions. The need for measurement
  • 6. 6Caring About Code Quality Cyclomatic complexity public void foo() { if (c1) { f1(); } else { f2(); } if (c2) { f3(); } else { f4(); } } • Upper bound for the number of test cases that are necessary to achieve a complete branch coverage • Lower bound for the number of paths through the control flow graph • Desirable value: below 10 Cyclomatic complexity: 3
  • 7. 7Caring About Code Quality Always leave the campground cleaner than you found it. The Boy Scout Rule
  • 8. 8Caring About Code Quality • Came from city crime researchers • A broken window will trigger a building into a smashed and abandoned derelict • So does the software Broken Window Theory
  • 9. 9Caring About Code Quality Composed method example public void add(Object element) { if (!readOnly) { int newSize = size + 1; if (newSize > elements.length) { Object[] newElements = new Object[elements.length + 10]; for (int index = 0; index < size; index++) { newElements[index] = elements[index]; elements = newElements; } } elements[size++] = element; } }
  • 10. 10Caring About Code Quality Implementation patterns
  • 11. 11Caring About Code Quality Composed method example public void add(Object element) { if (!isReadOnly()) { if (atCapacity()) { grow(); } addElement(element); } }
  • 12. 12Caring About Code Quality • Instant feedback • Allows you to make changes to code quickly • Help you understand the design of the code you are working on • Writing testable code helps to achieve better code quality • Unit tests are a form of sample code • Test-first forces you to plan before you code Advantages of Unit tests
  • 13. 13Caring About Code Quality • Whether the unit you're testing should be isolated from its collaborators • Mockist approach – Isolate from dependencies – More flexible in what you can test • Classic approach – No attempt to isolate unless communicating with the collaborator is awkward – Less brittle tests Unit tests collaborator isolation
  • 14. 14Caring About Code Quality • Change Risk Analysis and Prediction • Help you identify code that might be particularly difficult to understand, test, or maintain • 𝐶𝑅𝐴𝑃 𝑚 = cycl_comp(m)2 ∗ 1 − 𝑐𝑜𝑣𝑒𝑟𝑎𝑔𝑒 3 + cycl_comp(m) • A method with a CRAP score over 30 is considered unacceptable C.R.A.P. metric Cyclomatic Complexity Coverage required 0 – 5 0% 10 42% 15 57% 20 71% 25 80% 30 100% 31+ Not possible
  • 15. 15Caring About Code Quality • Don’t build complex machines • Don’t build frameworks • Make the software so simple that there are obviously no deficiencies • Keep it simple, stupid (KISS) Rube Goldberg Machines
  • 16. 16Caring About Code Quality • Avoid Cargo cult programming • Question authority • Accept feedback and give feedback Angry monkeys experiment
  • 17. 17Caring About Code Quality DESIGN PATTERNS IN PRACTICE 2019
  • 18. 18Caring About Code Quality Transfer object pattern
  • 19. 19Caring About Code Quality Front controller
  • 20. 20Caring About Code Quality Chain of responsibility
  • 21. 21Caring About Code Quality Proxy pattern
  • 22. 22Caring About Code Quality • Thread safety • Valid state • Encapsulation • Simpler to test • More readable and maintainable code Immutable Object
  • 23. 23Caring About Code Quality Null Object
  • 24. 24Caring About Code Quality Flyweight pattern
  • 25. 25Caring About Code Quality Template method
  • 26. 26Caring About Code Quality • State Pattern’s intent is to manage states of the object along with object’s behavior which changes with its state. • State typically involves a getStatus method and a reference back to the context • state, behavior is autodeterminated, strategy, behavior is determinated by caller. • Strategy Pattern is to have a family of interchangeable algorithms • Relation between individual states/individual strategies State vs Strategy
  • 27. 27Caring About Code Quality Observer Pattern
  • 28. 28Caring About Code Quality Facade Pattern
  • 29. 29Caring About Code Quality Decorator Pattern
  • 30. 30Caring About Code Quality THINKING AND CODING EFFICIENTLY
  • 31. 31Caring About Code Quality Effective Java • Level of access ? Minimum • Classpath ? • Composition vs inheritance • Avoid side effects • Minimize Mutability • Check methods/constructosr parameters for validity • Always override hashCode when you override equals • … • https://github.com/HugoMatilla/Effective-JAVA-Summary
  • 32. 32Caring About Code Quality • “This” keyword • Chained • Popular java Fluent API’s: – Java Object Oriented Querying (jOOQ) API – Java 8’s Date Time API – Java 9’s Money and Currency API Fluent API
  • 33. 33Caring About Code Quality • Handle UI interractions GRASP - The Controller
  • 34. 34Caring About Code Quality • Information expert • Encapsulating information GRASP - The Expert
  • 35. 35Caring About Code Quality • Creation responsibility • Have enough information to instantiate an object GRASP - The Creator
  • 36. 36Caring About Code Quality • it is a measure of how strongly related each piece of functionality expressed by the source code of a software module is. GRASP - High cohesion
  • 37. 37Caring About Code Quality • The smallest number of references between objects as possible • Reason of change GRASP - Low coupling
  • 38. 38Caring About Code Quality EMBZENZEKRI@SQLI.COM THANK YOU FOR ATTENTION! QUESTIONS?