SlideShare une entreprise Scribd logo
1  sur  20
1CONFIDENTIAL
Caring About Code
Quality
Tamas Korozsi
2015
2CONFIDENTIAL
ME
3CONFIDENTIAL
Clean Code: A Handbook of Agile Software Craftsmanship
by Robert C. Martin
The Book
4CONFIDENTIAL
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?
5CONFIDENTIAL
• 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
• Contains no duplicates
• Foundations are established on tiny abstractions
What is Clean Code after all?
6CONFIDENTIAL
• Subjective
• If you can’t measure, you can’t improve
• Identify what matters
• Defend and justify decisions.
The need for measurement
7CONFIDENTIAL
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
8CONFIDENTIAL
Always leave the campground
cleaner than you found it.
The Boy Scout Rule
9CONFIDENTIAL
• 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
10CONFIDENTIAL
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;
}
}
11CONFIDENTIAL
Implementation patterns
12CONFIDENTIAL
• Divide your program into methods that perform one identifiable task
• Keep all of the operation in a method at a same level of abstraction
• This will naturally result in programs with many small methods, each
few lines long.
Composed method pattern by Kent Beck
13CONFIDENTIAL
Composed method example
public void add(Object element) {
if (!isReadOnly()) {
if (atCapacity()) {
grow();
}
addElement(element);
}
}
14CONFIDENTIAL
• 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
15CONFIDENTIAL
• 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
16CONFIDENTIAL
• 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
17CONFIDENTIAL
• 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
18CONFIDENTIAL
• Avoid Cargo cult programming
• Question authority
• Accept feedback and give feedback
Angry monkeys experiment
19CONFIDENTIAL
EPAM Academy
Aniko_b
20CONFIDENTIAL
TAMAS_KOROZSI@EPAM.COM
THANK YOU FOR ATTENTION!
QUESTIONS?

Contenu connexe

Tendances

Tendances (20)

Keep your code clean
Keep your code cleanKeep your code clean
Keep your code clean
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
How to write maintainable code
How to write maintainable codeHow to write maintainable code
How to write maintainable code
 
Code quality
Code quality Code quality
Code quality
 
Code Quality
Code QualityCode Quality
Code Quality
 
Agile Testing
Agile TestingAgile Testing
Agile Testing
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
Coding standard
Coding standardCoding standard
Coding standard
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
TDD Anti-patterns (2022 edition)
TDD Anti-patterns (2022 edition)TDD Anti-patterns (2022 edition)
TDD Anti-patterns (2022 edition)
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
 
Clean Code
Clean CodeClean Code
Clean Code
 
Algorithm and Programming (Procedure and Function)
Algorithm and Programming (Procedure and Function)Algorithm and Programming (Procedure and Function)
Algorithm and Programming (Procedure and Function)
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Clean code
Clean codeClean code
Clean code
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Site reliability engineering
Site reliability engineeringSite reliability engineering
Site reliability engineering
 
My Laws of Test Driven Development (2023)
My Laws of Test Driven Development (2023)My Laws of Test Driven Development (2023)
My Laws of Test Driven Development (2023)
 
A Software Engineer
A Software EngineerA Software Engineer
A Software Engineer
 

Similaire à clean code - uncle bob

{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
AmalEldhose2
 
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best PracticesArch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
Igor Moochnick
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applications
nadeembtech
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
Seapine Software
 

Similaire à clean code - uncle bob (20)

Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
 
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
 
Clean Code Talk (draft)
Clean Code Talk (draft)Clean Code Talk (draft)
Clean Code Talk (draft)
 
Best pratice
Best praticeBest pratice
Best pratice
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
Clean code chpt_1
Clean code chpt_1Clean code chpt_1
Clean code chpt_1
 
TDD in Agile
TDD in AgileTDD in Agile
TDD in Agile
 
Is your code SOLID enough?
 Is your code SOLID enough? Is your code SOLID enough?
Is your code SOLID enough?
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best PracticesArch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applications
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd
TddTdd
Tdd
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Code Reviews
Code ReviewsCode Reviews
Code Reviews
 
Adopting Agile
Adopting AgileAdopting Agile
Adopting Agile
 
Writing clean and maintainable code
Writing clean and maintainable codeWriting clean and maintainable code
Writing clean and maintainable code
 

Plus de saber tabatabaee

لاراول ارائه 26 سپتامبر 2021 اسکایپ
لاراول ارائه 26 سپتامبر 2021 اسکایپلاراول ارائه 26 سپتامبر 2021 اسکایپ
لاراول ارائه 26 سپتامبر 2021 اسکایپ
saber tabatabaee
 

Plus de saber tabatabaee (16)

clean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxclean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
 
هاستینگ و راه اندازی یک پروژه لاراول - آنالیز و امکان سنجی
هاستینگ و راه اندازی یک پروژه لاراول - آنالیز و امکان سنجیهاستینگ و راه اندازی یک پروژه لاراول - آنالیز و امکان سنجی
هاستینگ و راه اندازی یک پروژه لاراول - آنالیز و امکان سنجی
 
لاراول ارائه 26 سپتامبر 2021 اسکایپ
لاراول ارائه 26 سپتامبر 2021 اسکایپلاراول ارائه 26 سپتامبر 2021 اسکایپ
لاراول ارائه 26 سپتامبر 2021 اسکایپ
 
scrum master اسکرام مستر
scrum master اسکرام مسترscrum master اسکرام مستر
scrum master اسکرام مستر
 
L5 swagger
L5 swaggerL5 swagger
L5 swagger
 
Crm or xrm
Crm or xrmCrm or xrm
Crm or xrm
 
Scrum master - daily scrum master story
Scrum master - daily scrum master storyScrum master - daily scrum master story
Scrum master - daily scrum master story
 
Online exam ismc
Online exam ismcOnline exam ismc
Online exam ismc
 
teaching data science students to write clean code
teaching data science students to write clean codeteaching data science students to write clean code
teaching data science students to write clean code
 
Writing clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingWriting clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancoding
 
R. herves. clean code (theme)2
R. herves. clean code (theme)2R. herves. clean code (theme)2
R. herves. clean code (theme)2
 
Code quality
Code qualityCode quality
Code quality
 
refactoring code by clean code rules
refactoring code by clean code rulesrefactoring code by clean code rules
refactoring code by clean code rules
 
sharepoint 2007 presentation in crcis
sharepoint 2007 presentation in crcis sharepoint 2007 presentation in crcis
sharepoint 2007 presentation in crcis
 
Linux DVD 03 Learnkey linux+ setup
Linux DVD 03 Learnkey linux+ setupLinux DVD 03 Learnkey linux+ setup
Linux DVD 03 Learnkey linux+ setup
 
linux+ learnkey DVD 2
linux+ learnkey DVD 2 linux+ learnkey DVD 2
linux+ learnkey DVD 2
 

Dernier

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 

clean code - uncle bob

  • 3. 3CONFIDENTIAL Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin The Book
  • 4. 4CONFIDENTIAL 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?
  • 5. 5CONFIDENTIAL • 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 • Contains no duplicates • Foundations are established on tiny abstractions What is Clean Code after all?
  • 6. 6CONFIDENTIAL • Subjective • If you can’t measure, you can’t improve • Identify what matters • Defend and justify decisions. The need for measurement
  • 7. 7CONFIDENTIAL 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
  • 8. 8CONFIDENTIAL Always leave the campground cleaner than you found it. The Boy Scout Rule
  • 9. 9CONFIDENTIAL • 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
  • 10. 10CONFIDENTIAL 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; } }
  • 12. 12CONFIDENTIAL • Divide your program into methods that perform one identifiable task • Keep all of the operation in a method at a same level of abstraction • This will naturally result in programs with many small methods, each few lines long. Composed method pattern by Kent Beck
  • 13. 13CONFIDENTIAL Composed method example public void add(Object element) { if (!isReadOnly()) { if (atCapacity()) { grow(); } addElement(element); } }
  • 14. 14CONFIDENTIAL • 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
  • 15. 15CONFIDENTIAL • 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
  • 16. 16CONFIDENTIAL • 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
  • 17. 17CONFIDENTIAL • 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
  • 18. 18CONFIDENTIAL • Avoid Cargo cult programming • Question authority • Accept feedback and give feedback Angry monkeys experiment