SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
CLEAN CODE

IT REALLY MATTERS
BROUGHT TO YOU
BY
SENIOR SOFTWARE
ENGINEER

DANIEL
KUMMER

NAMICS AG ZÜRICH
WWW.NAMICS.COM
CLEAN CODE
AGENDA

?

WHY

DOES IT EVEN
MATTER?

!

HOW

CAN IT BE
DONE?

*

BESIDE

THE CODE…
DEFINITION
OF CLEAN CODE

WORKS

EFFICIENT

READABLE

EXTENDABLE

CORRECTLY

IT TELLS YOU A STORY

SIMPLE

TO UNDERSTAND

IT DOES IT RIGHT
EASY TO MODIFY

CLEAN

SOMEONE CARED
?

WHY
CARE

	
   ”The only valid code metric is WTFs
per minute” ~ A comic strip	
  
SOFTWARE
ENTROPY

THE BROKEN WINDOW

DON’T LIVE WITH
BROKEN WINDOWS!
IT’S ALL
ABOUT

$$$	
  
THE COST OF
BAD CODE

TIME

PRODUCTIVITY

NERVES

PROJECTS

Mo$va$on	
  No	
  one	
  wants	
  to	
  take	
  it	
  
DETECTING
BAD CODE
DEAD CODE

UNUSED = UNNEEDED

COMMENTS
WHY NOT WHAT

A FEW
SMELLS
DUPLICATES

DON’T REPEAT YOURSELF

CONDITIONAL LONG METHOD / SPECULATIVE
COMPLEXITY PARAMETER LIST GENERALITY
HARD TO TEST

SHORTER = EASIER

SOLVE TODAYS PROBLEM,
NOT TOMORROWS

A more complete list can be found at http://www.codinghorror.com/blog/2006/05/code-smells.html
!

	
  

HOW
TO DO IT

“Any fool can write code that a computer
can understand.
Good programmers write code that
humans can understand.” ~Martin Fowler
2

SIMPLE
RULES

EASY TO FOLLOW	
  
1

WRITE DIRTY CODE
FIRST, THEN CLEAN IT
YOU CAN’T WRITE CLEAN CODE ON THE FIRST GO!
YOUR FIRST ATTEMPT WON’T BE YOUR BEST
SUCCESSIVE REFINEMENT IS KEY
START WITH PSEUDOCODE
2

LEAVE IT CLEANER
THAN YOU FOUND IT

THE “BOYSCOUT” RULE
INCREMENTIALISM – MAKE TINY CHANGES
EVEN IF IT’S JUST REFORMATTING – YOU CARED
YOU ARE TAKING RESPONSIBILITY
THREE WORDS

CARE FOR CODE
CLEAN
TIPPS

HOW TO GO ABOUT IT
NAMING CONVENTIONS
REVEAL INTENTION – CLARITY IS KING
no questions asked about the purpose

LONG NAMES AREN’T BAD

pick names corresponding to the scope

ONE WORD PER CONCEPT / NOT AMBIGUOUS
keep the lexicon consistent

USE ENGLISH – DON’T USE YOUR LANGUAGE
just don’t!
CODING
DRY - DON’T REPEAT YOURSELF
duplication is a root of evil!

DON’T OPTIMIZE PREMATURELY
unless it’s really, really necessary

DON’T SAVE ON CHARACTERS

one liners are not faster, just unreadable

DON’T TRY TO OUTSMART THE COMPILER
really smart people are working on it…
FUNCTIONS
KISS - KEEP IT SIMPLE AND STUPID
equals understandable

DO ONE THING ONLY – AND DO IT WELL
keep the level of abstraction to a minimum

MINIMIZE ARGUMENTS – LESS IS MORE

pursue it, as best as you can (think about testing)
FUNCTIONS
FLAGS ARE BAD

prefer polymorphism

SIDE EFFECTS ARE SCARY
the function should do one thing

EXTRACT ERROR HANDLING

improve readability, don’t obscure logic

RETURN ONCE ONLY – OR FAIL FAST
keep the exit clear
COMMENTING //drunk, fix later
NEVER EXPLAIN WHAT CODE DOES
explain WHY you did it this way

DON’T COMMENT OUT CODE
we have VCS for this!

COMMENT STRANGE OR UNNATURAL CODE
do it even if it’s not your own – explain why

NO REDUNDANT OR MANDATED COMMENTS
example: don’t document getters / setters
FORMATTING DO IT LIKE THE NEWSPAPERS

{

TOP-DOWN PRINCIPLE
MAIN FUNCTIONS ON TOP
FOLLOWED BY CALLED FUNCTIONS

}

VERTICAL DENSITY
WHAT BELONGS TOGETHER
SHOULD BE TOGETHER

NO HORIZONTAL ALIGNMENT
DON’T ALIGN JUST FOR THE LOOKS
OBJECTS AND CLASSES
SRP – SINGLE RESPONSIBILITY PRINCIPLE
one responsibility per object

SMALL

keep away from the “god”-classes

ORGANIZE FOR CHANGE – USE INTERFACES
it’s most likely going to happen

LoD - LAW OF DEMETER (LOOSE COUPLING)
a given object should assume as little as possible
about the structure or properties of anything else
ERROR HANDLING
USE UNCHECKED EXCEPTIONS AND
DOCUMENT THEM IN THE JAVADOC
you decide when to handle them

EXTRACT HANDLING BLOCKS (TRY/CATCH)
don’t disturb the code flow

DON’T RETURN NULL, DON’T PASS NULL
avoid NULL checks and NPEs

CONCENTRATE ON WHAT YOU CAN HANDLE
not what to throw
TEST
YOUR CREATION
SO YOU MAY SLEEP CALM AT NIGHT
THE F.I.R.S.T PRINCIPLE
FAST

tests should run quick – or you won’t run them

INDEPENDENT

no test should depend on another test

REPEATABLE

in any environment, your laptop, the CI server…

SELF-VALIDATING

pass or fail - no manual action required

TIMELY

don’t write your tests too late, it only gets harder
TESTING PYRAMID
BESIDE
CODE

THE SATELLITES OF
A SOFTWARE PROJECT	
  
USE TOOLS

COMBINE YOUR MAGIC HELPERS
CONTINUOUS INTEGRATION
EARLY PROBLEM RECOGNITION

RELEASE MANAGEMENT

SCM / VSC

ISSUE MANAGEMENT

CODE METRICS

DEFINE YOUR RELEASE CYCLES

TRACK DISCUSSIONS AND DESCISSIONS

KEEP A CLEAR HISTORY

HEURISTIC CODE ANALYSIS
HUMAN FACTORS
DON’T BE SHY…

OTHERS HAVE THE SAME PROBLEMS YOU HAVE – EVEN PROS!

REVIEW

LEARN

DISCUSS

SHARE

IMPROVE AND LEARN

GUIDELINES / PROBLEMS / SOLUTIONS

DELIBERATE PRACTICE

THOUGHTS / TOOLS / IDEAS
GOING
DEEPER

more about everything…
READING MATERIAL

SOFTWARE
CRAFTSMANSHIP

CODE OF CONDUCT

CLEAN YOUR CODE
WITH COMMON
SOLUTIONS
CLEAN CODE
DEPENDS ON

YOU

Weitere ähnliche Inhalte

Was ist angesagt?

Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVMSylvain Wallez
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Edureka!
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooksSamundra khatri
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Edureka!
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react formYao Nien Chung
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 

Was ist angesagt? (20)

Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Clean code
Clean codeClean code
Clean code
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
React Hooks
React HooksReact Hooks
React Hooks
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 

Ähnlich wie Clean Code

Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous IntegrationGraceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous IntegrationChris B. France
 
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testingJoel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testingIT Arena
 
Mind the Gap - State of the Browser 2015
Mind the Gap - State of the Browser 2015Mind the Gap - State of the Browser 2015
Mind the Gap - State of the Browser 2015Christian Heilmann
 
Red teaming the CCDC
Red teaming the CCDCRed teaming the CCDC
Red teaming the CCDCscriptjunkie
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic RevisitedAdam Keys
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsSteven Smith
 
Zero to tested
Zero to testedZero to tested
Zero to testedMagenTys
 
Back to basics simple, elegant, beautiful code
Back to basics   simple, elegant, beautiful codeBack to basics   simple, elegant, beautiful code
Back to basics simple, elegant, beautiful codeAndrew Harcourt
 
Streams on top of scala - #lambdaCon
Streams on top of scala - #lambdaConStreams on top of scala - #lambdaCon
Streams on top of scala - #lambdaConQuentin Adam
 
Immutability - open source summit paris 2015
Immutability - open source summit paris 2015Immutability - open source summit paris 2015
Immutability - open source summit paris 2015Quentin Adam
 
You shouldneverdo
You shouldneverdoYou shouldneverdo
You shouldneverdodaniil3
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential SkillsJohn Choi
 
Chaos Engineering Without Observability ... Is Just Chaos
Chaos Engineering Without Observability ... Is Just ChaosChaos Engineering Without Observability ... Is Just Chaos
Chaos Engineering Without Observability ... Is Just ChaosCharity Majors
 
Automated Software Testing
Automated Software TestingAutomated Software Testing
Automated Software TestingRay Nicholus
 

Ähnlich wie Clean Code (20)

Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous IntegrationGraceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
 
Tdd vs SQL
Tdd vs SQLTdd vs SQL
Tdd vs SQL
 
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testingJoel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
Joel Arvidsson, Klarna. What You See is What You Get – a case for visual testing
 
Mind the Gap - State of the Browser 2015
Mind the Gap - State of the Browser 2015Mind the Gap - State of the Browser 2015
Mind the Gap - State of the Browser 2015
 
TxJS 2011
TxJS 2011TxJS 2011
TxJS 2011
 
Red teaming the CCDC
Red teaming the CCDCRed teaming the CCDC
Red teaming the CCDC
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Good programming
Good programmingGood programming
Good programming
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
 
Zero to tested
Zero to testedZero to tested
Zero to tested
 
Back to basics simple, elegant, beautiful code
Back to basics   simple, elegant, beautiful codeBack to basics   simple, elegant, beautiful code
Back to basics simple, elegant, beautiful code
 
Coding standard
Coding standardCoding standard
Coding standard
 
Clean Code
Clean CodeClean Code
Clean Code
 
Streams on top of scala - #lambdaCon
Streams on top of scala - #lambdaConStreams on top of scala - #lambdaCon
Streams on top of scala - #lambdaCon
 
Immutability - open source summit paris 2015
Immutability - open source summit paris 2015Immutability - open source summit paris 2015
Immutability - open source summit paris 2015
 
You shouldneverdo
You shouldneverdoYou shouldneverdo
You shouldneverdo
 
Minimalism
MinimalismMinimalism
Minimalism
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
 
Chaos Engineering Without Observability ... Is Just Chaos
Chaos Engineering Without Observability ... Is Just ChaosChaos Engineering Without Observability ... Is Just Chaos
Chaos Engineering Without Observability ... Is Just Chaos
 
Automated Software Testing
Automated Software TestingAutomated Software Testing
Automated Software Testing
 

Mehr von Daniel Kummer

DIY IoT - The InfoDome
DIY IoT - The InfoDomeDIY IoT - The InfoDome
DIY IoT - The InfoDomeDaniel Kummer
 
Bluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the BulletsBluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the BulletsDaniel Kummer
 
Changing internet - where we come from where we go
Changing internet - where we come from where we goChanging internet - where we come from where we go
Changing internet - where we come from where we goDaniel Kummer
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use ItDaniel Kummer
 
Magnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - StorytellingMagnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - StorytellingDaniel Kummer
 
Code Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practiceCode Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practiceDaniel Kummer
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumberDaniel Kummer
 
Git get-the-job-done
Git get-the-job-doneGit get-the-job-done
Git get-the-job-doneDaniel Kummer
 

Mehr von Daniel Kummer (12)

Git code reviews
Git code reviewsGit code reviews
Git code reviews
 
DIY IoT - The InfoDome
DIY IoT - The InfoDomeDIY IoT - The InfoDome
DIY IoT - The InfoDome
 
Bluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the BulletsBluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the Bullets
 
HTTP
HTTPHTTP
HTTP
 
Changing internet - where we come from where we go
Changing internet - where we come from where we goChanging internet - where we come from where we go
Changing internet - where we come from where we go
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Magnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - StorytellingMagnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - Storytelling
 
Code Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practiceCode Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practice
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Git get-the-job-done
Git get-the-job-doneGit get-the-job-done
Git get-the-job-done
 
Git
GitGit
Git
 
Git! Why? How?
Git! Why? How?Git! Why? How?
Git! Why? How?
 

Kürzlich hochgeladen

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Kürzlich hochgeladen (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Clean Code

  • 1. CLEAN CODE IT REALLY MATTERS BROUGHT TO YOU BY SENIOR SOFTWARE ENGINEER DANIEL KUMMER NAMICS AG ZÜRICH WWW.NAMICS.COM
  • 2. CLEAN CODE AGENDA ? WHY DOES IT EVEN MATTER? ! HOW CAN IT BE DONE? * BESIDE THE CODE…
  • 3. DEFINITION OF CLEAN CODE WORKS EFFICIENT READABLE EXTENDABLE CORRECTLY IT TELLS YOU A STORY SIMPLE TO UNDERSTAND IT DOES IT RIGHT EASY TO MODIFY CLEAN SOMEONE CARED
  • 4. ? WHY CARE   ”The only valid code metric is WTFs per minute” ~ A comic strip  
  • 5. SOFTWARE ENTROPY THE BROKEN WINDOW DON’T LIVE WITH BROKEN WINDOWS!
  • 6. IT’S ALL ABOUT $$$   THE COST OF BAD CODE TIME PRODUCTIVITY NERVES PROJECTS Mo$va$on  No  one  wants  to  take  it  
  • 7. DETECTING BAD CODE DEAD CODE UNUSED = UNNEEDED COMMENTS WHY NOT WHAT A FEW SMELLS DUPLICATES DON’T REPEAT YOURSELF CONDITIONAL LONG METHOD / SPECULATIVE COMPLEXITY PARAMETER LIST GENERALITY HARD TO TEST SHORTER = EASIER SOLVE TODAYS PROBLEM, NOT TOMORROWS A more complete list can be found at http://www.codinghorror.com/blog/2006/05/code-smells.html
  • 8. !   HOW TO DO IT “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” ~Martin Fowler
  • 10. 1 WRITE DIRTY CODE FIRST, THEN CLEAN IT YOU CAN’T WRITE CLEAN CODE ON THE FIRST GO! YOUR FIRST ATTEMPT WON’T BE YOUR BEST SUCCESSIVE REFINEMENT IS KEY START WITH PSEUDOCODE
  • 11. 2 LEAVE IT CLEANER THAN YOU FOUND IT THE “BOYSCOUT” RULE INCREMENTIALISM – MAKE TINY CHANGES EVEN IF IT’S JUST REFORMATTING – YOU CARED YOU ARE TAKING RESPONSIBILITY
  • 14. NAMING CONVENTIONS REVEAL INTENTION – CLARITY IS KING no questions asked about the purpose LONG NAMES AREN’T BAD pick names corresponding to the scope ONE WORD PER CONCEPT / NOT AMBIGUOUS keep the lexicon consistent USE ENGLISH – DON’T USE YOUR LANGUAGE just don’t!
  • 15. CODING DRY - DON’T REPEAT YOURSELF duplication is a root of evil! DON’T OPTIMIZE PREMATURELY unless it’s really, really necessary DON’T SAVE ON CHARACTERS one liners are not faster, just unreadable DON’T TRY TO OUTSMART THE COMPILER really smart people are working on it…
  • 16. FUNCTIONS KISS - KEEP IT SIMPLE AND STUPID equals understandable DO ONE THING ONLY – AND DO IT WELL keep the level of abstraction to a minimum MINIMIZE ARGUMENTS – LESS IS MORE pursue it, as best as you can (think about testing)
  • 17. FUNCTIONS FLAGS ARE BAD prefer polymorphism SIDE EFFECTS ARE SCARY the function should do one thing EXTRACT ERROR HANDLING improve readability, don’t obscure logic RETURN ONCE ONLY – OR FAIL FAST keep the exit clear
  • 18. COMMENTING //drunk, fix later NEVER EXPLAIN WHAT CODE DOES explain WHY you did it this way DON’T COMMENT OUT CODE we have VCS for this! COMMENT STRANGE OR UNNATURAL CODE do it even if it’s not your own – explain why NO REDUNDANT OR MANDATED COMMENTS example: don’t document getters / setters
  • 19. FORMATTING DO IT LIKE THE NEWSPAPERS { TOP-DOWN PRINCIPLE MAIN FUNCTIONS ON TOP FOLLOWED BY CALLED FUNCTIONS } VERTICAL DENSITY WHAT BELONGS TOGETHER SHOULD BE TOGETHER NO HORIZONTAL ALIGNMENT DON’T ALIGN JUST FOR THE LOOKS
  • 20. OBJECTS AND CLASSES SRP – SINGLE RESPONSIBILITY PRINCIPLE one responsibility per object SMALL keep away from the “god”-classes ORGANIZE FOR CHANGE – USE INTERFACES it’s most likely going to happen LoD - LAW OF DEMETER (LOOSE COUPLING) a given object should assume as little as possible about the structure or properties of anything else
  • 21. ERROR HANDLING USE UNCHECKED EXCEPTIONS AND DOCUMENT THEM IN THE JAVADOC you decide when to handle them EXTRACT HANDLING BLOCKS (TRY/CATCH) don’t disturb the code flow DON’T RETURN NULL, DON’T PASS NULL avoid NULL checks and NPEs CONCENTRATE ON WHAT YOU CAN HANDLE not what to throw
  • 22. TEST YOUR CREATION SO YOU MAY SLEEP CALM AT NIGHT
  • 23. THE F.I.R.S.T PRINCIPLE FAST tests should run quick – or you won’t run them INDEPENDENT no test should depend on another test REPEATABLE in any environment, your laptop, the CI server… SELF-VALIDATING pass or fail - no manual action required TIMELY don’t write your tests too late, it only gets harder
  • 25. BESIDE CODE THE SATELLITES OF A SOFTWARE PROJECT  
  • 26. USE TOOLS COMBINE YOUR MAGIC HELPERS CONTINUOUS INTEGRATION EARLY PROBLEM RECOGNITION RELEASE MANAGEMENT SCM / VSC ISSUE MANAGEMENT CODE METRICS DEFINE YOUR RELEASE CYCLES TRACK DISCUSSIONS AND DESCISSIONS KEEP A CLEAR HISTORY HEURISTIC CODE ANALYSIS
  • 27. HUMAN FACTORS DON’T BE SHY… OTHERS HAVE THE SAME PROBLEMS YOU HAVE – EVEN PROS! REVIEW LEARN DISCUSS SHARE IMPROVE AND LEARN GUIDELINES / PROBLEMS / SOLUTIONS DELIBERATE PRACTICE THOUGHTS / TOOLS / IDEAS
  • 29. READING MATERIAL SOFTWARE CRAFTSMANSHIP CODE OF CONDUCT CLEAN YOUR CODE WITH COMMON SOLUTIONS