SlideShare a Scribd company logo
CLEAN CODE
SIRAR SALIH
.NET CONSULTANT
In theory, it’s about...

SOLID

16.01.2014

/

2
In theory, it’s about...

S ingle responsibility principle
O pen/closed principle
L iskov substitution principle
I nterface segragation principle
D ependency inversion principle
16.01.2014

/

3
In practice, it’s all about... RTM

Readability
Testability
Maintainability

16.01.2014

/

4
Readable Code

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth

16.01.2014

/

5
Readable Code

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth
From http://www.osnews.com

16.01.2014

/

6
Readable Code

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth

From Pluralsight

16.01.2014

/

7
Readable Code
• Readable code is understandable code
• Naming
 Class names
 Context specific
 Method names
 Say exactly what they do
• The don’ts
 Don’t confuse
 Don’t hide
 Don’t joke
 Don’t be informal
• Tell a story!
«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth

16.01.2014

/

8
Readable Code

Bad

«Programming is the art of telling another human what
one wants the computer to do.» - Donald Knuth

Better

16.01.2014

/

9
Testable Code
•
•
•
•
•
•
•

Making it testable, is making it clean
Isolation
Decoupling
Separation of concerns
TDD
Design
Clean is the side effect of testable

16.01.2014 /

10
Testable Code

«You know you should be unit testing, so
why aren’t you doing it?» - Roy Osherove

16.01.2014 /

11
Testable Code
Bad

Good

16.01.2014 /

12
Maintainable Code

16.01.2014 /

13
Maintainable Code
•
•
•
•
•
•
•

Easy to extend
A change requires one change, not ten
Easy to understand
Unbrittle
Test coverage
Spreads optimism
Importance level: Readable > maintainable

16.01.2014 /

14
Bad Code

16.01.2014 /

15
Good Code

16.01.2014 /

16
The Evil Cycle

From http://blog.codeclimate.com/

16.01.2014 /

17
Be an Agent of Change

16.01.2014 /

18
Fight Code Smells and Anti-Patterns
•
•
•
•
•
•
•
•

Comments
Duplication
Global objects
Magic numbers
Circular dependency
Coupling
Nesting
Dead code

16.01.2014 /

19
Make it Routine

16.01.2014 /

20
Recommended Books

16.01.2014 /

21
Thank you  / Questions

Blog: http://sirars.com/
• sirar.salih@itera.no / sirars@gmail.com
• @SirarSalih

More Related Content

Similar to Clean Code

Torocpsummit 130116180230-phpapp02
Torocpsummit 130116180230-phpapp02Torocpsummit 130116180230-phpapp02
Torocpsummit 130116180230-phpapp02
King Parmeshwar Pawar :) Edu.Li
 
Session 2 - Libraries and Open Source
Session 2 - Libraries and Open SourceSession 2 - Libraries and Open Source
Session 2 - Libraries and Open Source
Jonathan Field
 
10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning
Christopher Mohritz
 
Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017
Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017
Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017
Codemotion
 
Crafting Great Code
Crafting Great CodeCrafting Great Code
Crafting Great Code
Harold Shinsato
 
10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning
10x Nation
 
FoundationsOfUserInterfaceDesign
FoundationsOfUserInterfaceDesignFoundationsOfUserInterfaceDesign
FoundationsOfUserInterfaceDesign
Sinsentido2
 
Everyone's a Coder Now: Reading and Writing Technical Code
Everyone's a Coder Now: Reading and Writing Technical CodeEveryone's a Coder Now: Reading and Writing Technical Code
Everyone's a Coder Now: Reading and Writing Technical Code
Julie Meloni
 
New text document
New text documentNew text document
New text document
sleucwnq
 
New text document
New text documentNew text document
New text document
sleucwnq
 
Are Computer Ethical Issues Unique ?
Are Computer Ethical Issues Unique ?Are Computer Ethical Issues Unique ?
Are Computer Ethical Issues Unique ?
VARUN KUMAR
 
Blackhat 2014 Conference and Defcon 22
Blackhat 2014 Conference and Defcon 22 Blackhat 2014 Conference and Defcon 22
Blackhat 2014 Conference and Defcon 22
dandb-technology
 
Foss final seminar
Foss final seminarFoss final seminar
Foss final seminar
Smit Patil
 
Foss final seminar
Foss final seminarFoss final seminar
Foss final seminar
Smit Patil
 
Design of everyday things fundamental principles of interaction - V2
Design of everyday things   fundamental principles of interaction - V2Design of everyday things   fundamental principles of interaction - V2
Design of everyday things fundamental principles of interaction - V2
Isaac Liao
 
Automate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPT
Automate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPTAutomate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPT
Automate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPT
Anant Corporation
 
Designing for mobile. A UX perspective for developers
Designing for mobile. A UX perspective for developersDesigning for mobile. A UX perspective for developers
Designing for mobile. A UX perspective for developers
Oscar Gonzalez Garza
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 
Open source a presentation
Open source   a presentationOpen source   a presentation
Open source a presentation
Amol Vidwans
 
The Past and Future of Open Computing
The Past and Future of Open ComputingThe Past and Future of Open Computing
The Past and Future of Open Computing
Tim O'Reilly
 

Similar to Clean Code (20)

Torocpsummit 130116180230-phpapp02
Torocpsummit 130116180230-phpapp02Torocpsummit 130116180230-phpapp02
Torocpsummit 130116180230-phpapp02
 
Session 2 - Libraries and Open Source
Session 2 - Libraries and Open SourceSession 2 - Libraries and Open Source
Session 2 - Libraries and Open Source
 
10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning
 
Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017
Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017
Death by a thousand paper cuts — Alexandra Leisse - Codemotion Amsterdam 2017
 
Crafting Great Code
Crafting Great CodeCrafting Great Code
Crafting Great Code
 
10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning10 Things Every PHP Developer Should Know About Machine Learning
10 Things Every PHP Developer Should Know About Machine Learning
 
FoundationsOfUserInterfaceDesign
FoundationsOfUserInterfaceDesignFoundationsOfUserInterfaceDesign
FoundationsOfUserInterfaceDesign
 
Everyone's a Coder Now: Reading and Writing Technical Code
Everyone's a Coder Now: Reading and Writing Technical CodeEveryone's a Coder Now: Reading and Writing Technical Code
Everyone's a Coder Now: Reading and Writing Technical Code
 
New text document
New text documentNew text document
New text document
 
New text document
New text documentNew text document
New text document
 
Are Computer Ethical Issues Unique ?
Are Computer Ethical Issues Unique ?Are Computer Ethical Issues Unique ?
Are Computer Ethical Issues Unique ?
 
Blackhat 2014 Conference and Defcon 22
Blackhat 2014 Conference and Defcon 22 Blackhat 2014 Conference and Defcon 22
Blackhat 2014 Conference and Defcon 22
 
Foss final seminar
Foss final seminarFoss final seminar
Foss final seminar
 
Foss final seminar
Foss final seminarFoss final seminar
Foss final seminar
 
Design of everyday things fundamental principles of interaction - V2
Design of everyday things   fundamental principles of interaction - V2Design of everyday things   fundamental principles of interaction - V2
Design of everyday things fundamental principles of interaction - V2
 
Automate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPT
Automate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPTAutomate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPT
Automate your Job and Business with ChatGPT #3 - Fundamentals of LLM/GPT
 
Designing for mobile. A UX perspective for developers
Designing for mobile. A UX perspective for developersDesigning for mobile. A UX perspective for developers
Designing for mobile. A UX perspective for developers
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Open source a presentation
Open source   a presentationOpen source   a presentation
Open source a presentation
 
The Past and Future of Open Computing
The Past and Future of Open ComputingThe Past and Future of Open Computing
The Past and Future of Open Computing
 

More from Sirar Salih

Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)
Sirar Salih
 
Azure Table Storage: The Good, the Bad, the Ugly (full talk)
Azure Table Storage: The Good, the Bad, the Ugly (full talk)Azure Table Storage: The Good, the Bad, the Ugly (full talk)
Azure Table Storage: The Good, the Bad, the Ugly (full talk)
Sirar Salih
 
Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)
Sirar Salih
 
Test Driven Development with AngularJS
Test Driven Development with AngularJSTest Driven Development with AngularJS
Test Driven Development with AngularJS
Sirar Salih
 
One Framework to Rule Them All
One Framework to Rule Them AllOne Framework to Rule Them All
One Framework to Rule Them All
Sirar Salih
 
Introduction to WPF and MVVM
Introduction to WPF and MVVMIntroduction to WPF and MVVM
Introduction to WPF and MVVM
Sirar Salih
 
Angularfying Your ASP.NET MVC APP
Angularfying Your ASP.NET MVC APPAngularfying Your ASP.NET MVC APP
Angularfying Your ASP.NET MVC APP
Sirar Salih
 

More from Sirar Salih (7)

Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (15 min. lightning talk)
 
Azure Table Storage: The Good, the Bad, the Ugly (full talk)
Azure Table Storage: The Good, the Bad, the Ugly (full talk)Azure Table Storage: The Good, the Bad, the Ugly (full talk)
Azure Table Storage: The Good, the Bad, the Ugly (full talk)
 
Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)
Azure Table Storage: The Good, the Bad, the Ugly (10 min. lightning talk)
 
Test Driven Development with AngularJS
Test Driven Development with AngularJSTest Driven Development with AngularJS
Test Driven Development with AngularJS
 
One Framework to Rule Them All
One Framework to Rule Them AllOne Framework to Rule Them All
One Framework to Rule Them All
 
Introduction to WPF and MVVM
Introduction to WPF and MVVMIntroduction to WPF and MVVM
Introduction to WPF and MVVM
 
Angularfying Your ASP.NET MVC APP
Angularfying Your ASP.NET MVC APPAngularfying Your ASP.NET MVC APP
Angularfying Your ASP.NET MVC APP
 

Recently uploaded

JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 

Recently uploaded (20)

JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 

Clean Code

Editor's Notes

  1. Single responsibility principlethe notion that an object should have only a single responsibility.Open/closed principlethe notion that “software entities … should be open for extension, but closed for modification”.Liskov substitution principlethe notion that “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”. Interface segregation principlethe notion that “many client specific interfaces are better than one general purpose interface.”Dependency inversion principlethe notion that one should “Depend upon Abstractions. Do not depend upon concretions.”[5]Dependency injection is one method of following this principle.