SlideShare a Scribd company logo
Clean code
Nguyen Quang Duc
Contents
▪ What is clean code, bad code
▪ Why it matters
▪ Meaningful names and formatting
▪ Functions
▪ Comments
Clean code vs bad code
Clean code
▪ Easy to understand
▪ Easy to maintain
▪ Easy to extend
Bad code
▪ Mysterious
▪ Fragile
▪ Dangerous
Why do we write bad code
▪ Tight schedule
▪ Tired of project
▪ Get working now, clean up later (or never)
▪ Everybody does it!
Why should we write clean code
▪ We spent most of our time reading rather than writing
▪ Bad code will cost you:
▪ Time
▪ Money
▪ Relationship
▪ Talent
The boy scout rule
▪ Leave the campground cleaner than you found it.
How do we write clean
code
Meaningful names
▪ Use Intention-Revealing Names
▪ Don’t be afraid of longer names, the name should say everything about it.
▪ Avoid abbreviation
This is bad:
protected $d;
This is good:
protected $elapsedTimeInDays;
protected $daysSinceCreation;
protected $daysSinceModification;
protected $fileAgeInDays;
▪ Use pronounceable name
This is bad:
public $genymdhms;
public $modymdhms;
This is good:
public $generationTimestamp;
public $modificationTimestamp;
▪ Use one word per concept
Be consistent. For example, don’t use get and fetch to do the same thing in different classes
▪ Use verbs for function names and nouns for classes and attributes
Formatting
▪ Follow a single coding style
▪ There is no obvious "best" style. Just being consistent.
▪ Each line should be composed of a single expression.
▪ Each block should present a single thought.
▪ Blocks should be separated with a single, empty line.
▪ A line of the code should not exceed 80 characters
▪ Our eyes are more comfortable when reading tall and narrow columns of text
▪ Use indentation and alignment to improve the readability
Functions
▪ The smaller the better
▪ A function should only do one thing
▪ No nested control structure
▪ Less arguments are better
▪ No side effects
▪ Avoid output arguments
▪ Don’t repeat yourself
Hard to read Easy to understand
Comments
▪ Don’t comment bad code, rewrite it
▪ If code is readable you don’t need comments
▪ Explain your intention in comments
▪ Warn of consequences in comments
▪ Emphasis important points in comments
▪ Always have you PHPDoc comments
▪ Noise comments are bad
▪ Never leave code commented
▪ The best comment is the code itself
For example:
// check if customer can buy products
if ($customer->isActive() && $customer->getAge() > 65)
is not as good as:
if ($customer->canBuyProducts())
▪ Avoid obvious comments
▪ Other kind of useful comments
Legal comments, e.g. // Copyright (c) 2014 Magento Inc.
Informative comments, e.g. // Returns an instance of a Customer object
Purpose-explaining comments, e.g. return 1; // it is default value
Warning comments, e.g. // very slow query, don’t use if you don’t need to
TODO comments, e.g. // @TODO rewrite this query
Reference
▪ Clean Code: A Handbook of Agile
Software Craftsmanship by Robert
C. Martin
▪ http://www.slideshare.net/mariosa
ngiorgio/clean-code-and-code-
smells
▪ http://www.slideshare.net/JandV/c
lean-code-summary
▪ http://www.slideshare.net/josedasi
lva/phplx

More Related Content

What's hot

Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
Mario Sangiorgio
 
Clean Code
Clean CodeClean Code
Clean Code
swaraj Patil
 
Clean code
Clean codeClean code
Clean code
ifnu bima
 
Clean code
Clean codeClean code
Clean code
Henrique Smoco
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
YeurDreamin'
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summary
Jan de Vries
 
Clean Code
Clean CodeClean Code
Clean Code
Dmytro Turskyi
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
Kent Huang
 
Clean code
Clean codeClean code
Clean code
Knoldus Inc.
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Namenahid035
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
Theo Jungeblut
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Victor Rentea
 
Clean Code
Clean CodeClean Code
Clean Code
Victor Rentea
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean code
Victor Rentea
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
Bhavin Gandhi
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
Angel Garcia Olloqui
 
The Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring FrameworkThe Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring Framework
Victor Rentea
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
Theo Jungeblut
 
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampClean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Theo Jungeblut
 

What's hot (20)

Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean code
Clean codeClean code
Clean code
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Clean code
Clean codeClean code
Clean code
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summary
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Clean code
Clean codeClean code
Clean code
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Name
 
Clean Code III - Software Craftsmanship
Clean Code III - Software CraftsmanshipClean Code III - Software Craftsmanship
Clean Code III - Software Craftsmanship
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 
Clean Code
Clean CodeClean Code
Clean Code
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean code
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
 
The Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring FrameworkThe Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring Framework
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampClean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
 

Similar to Clean code

AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Gavin Pickin
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
Ortus Solutions, Corp
 
Striving towards better PHP code
Striving towards better PHP codeStriving towards better PHP code
Striving towards better PHP code
Steve Maraspin
 
Clean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesClean Code and Common Engineering Practices
Clean Code and Common Engineering Practices
Ruth Sperer
 
CLEAN WEB
CLEAN WEBCLEAN WEB
CLEAN WEB
Seda Yalçın
 
As a Salesforce Developer I will... 7 Ground Rules for Success, Robert Sösemann
As a Salesforce Developer I will... 7 Ground Rules for Success, Robert SösemannAs a Salesforce Developer I will... 7 Ground Rules for Success, Robert Sösemann
As a Salesforce Developer I will... 7 Ground Rules for Success, Robert Sösemann
CzechDreamin
 
Clean code
Clean codeClean code
Clean code
Uday Pratap Singh
 
Raya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityRaya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readability
Abdel Hady Muhammad
 
Clean Code Pt I
Clean Code Pt IClean Code Pt I
Clean Code Pt I
Paul Boocock
 
Whats Preventing Me To Write Nearly Accurate Code.Key
Whats Preventing Me To Write Nearly Accurate Code.KeyWhats Preventing Me To Write Nearly Accurate Code.Key
Whats Preventing Me To Write Nearly Accurate Code.Keynhm taveer hossain khan
 
Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptx
MukundSonaiya1
 
Seven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC OsloSeven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC Oslo
Christian Heilmann
 
Managing Tech Teams
Managing Tech TeamsManaging Tech Teams
Managing Tech Teams
Scott Davis
 
PHP Dublin Meetup - Clean Code in PHP
PHP Dublin Meetup - Clean Code in PHPPHP Dublin Meetup - Clean Code in PHP
PHP Dublin Meetup - Clean Code in PHP
Paras Sood
 
Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...
Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...
Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...
TopCV Vietnam
 
Software Design Notes
Software Design NotesSoftware Design Notes
Software Design Notes
Diego Pacheco
 
Олег Мізьов "Reading between lines" Lviv Project Management Day 2017
Олег Мізьов "Reading between lines" Lviv Project Management Day 2017Олег Мізьов "Reading between lines" Lviv Project Management Day 2017
Олег Мізьов "Reading between lines" Lviv Project Management Day 2017
Lviv Startup Club
 
Can my underperforming law firm website be saved?
Can my underperforming law firm website be saved?Can my underperforming law firm website be saved?
Can my underperforming law firm website be saved?
Dan Jaffe
 
Sanely working with Legacy Code - PyTexas 2024
Sanely working with Legacy Code - PyTexas 2024Sanely working with Legacy Code - PyTexas 2024
Sanely working with Legacy Code - PyTexas 2024
Joe Cabrera
 
CLEAN CODE
CLEAN CODECLEAN CODE
CLEAN CODE
Knoldus Inc.
 

Similar to Clean code (20)

AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
 
Striving towards better PHP code
Striving towards better PHP codeStriving towards better PHP code
Striving towards better PHP code
 
Clean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesClean Code and Common Engineering Practices
Clean Code and Common Engineering Practices
 
CLEAN WEB
CLEAN WEBCLEAN WEB
CLEAN WEB
 
As a Salesforce Developer I will... 7 Ground Rules for Success, Robert Sösemann
As a Salesforce Developer I will... 7 Ground Rules for Success, Robert SösemannAs a Salesforce Developer I will... 7 Ground Rules for Success, Robert Sösemann
As a Salesforce Developer I will... 7 Ground Rules for Success, Robert Sösemann
 
Clean code
Clean codeClean code
Clean code
 
Raya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityRaya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readability
 
Clean Code Pt I
Clean Code Pt IClean Code Pt I
Clean Code Pt I
 
Whats Preventing Me To Write Nearly Accurate Code.Key
Whats Preventing Me To Write Nearly Accurate Code.KeyWhats Preventing Me To Write Nearly Accurate Code.Key
Whats Preventing Me To Write Nearly Accurate Code.Key
 
Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptx
 
Seven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC OsloSeven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC Oslo
 
Managing Tech Teams
Managing Tech TeamsManaging Tech Teams
Managing Tech Teams
 
PHP Dublin Meetup - Clean Code in PHP
PHP Dublin Meetup - Clean Code in PHPPHP Dublin Meetup - Clean Code in PHP
PHP Dublin Meetup - Clean Code in PHP
 
Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...
Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...
Huong dan viet cv cho Lap Trinh Vien, Cach phong van xin viec hieu qua - TopC...
 
Software Design Notes
Software Design NotesSoftware Design Notes
Software Design Notes
 
Олег Мізьов "Reading between lines" Lviv Project Management Day 2017
Олег Мізьов "Reading between lines" Lviv Project Management Day 2017Олег Мізьов "Reading between lines" Lviv Project Management Day 2017
Олег Мізьов "Reading between lines" Lviv Project Management Day 2017
 
Can my underperforming law firm website be saved?
Can my underperforming law firm website be saved?Can my underperforming law firm website be saved?
Can my underperforming law firm website be saved?
 
Sanely working with Legacy Code - PyTexas 2024
Sanely working with Legacy Code - PyTexas 2024Sanely working with Legacy Code - PyTexas 2024
Sanely working with Legacy Code - PyTexas 2024
 
CLEAN CODE
CLEAN CODECLEAN CODE
CLEAN CODE
 

Recently uploaded

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 

Recently uploaded (20)

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 

Clean code

  • 2. Contents ▪ What is clean code, bad code ▪ Why it matters ▪ Meaningful names and formatting ▪ Functions ▪ Comments
  • 3. Clean code vs bad code Clean code ▪ Easy to understand ▪ Easy to maintain ▪ Easy to extend Bad code ▪ Mysterious ▪ Fragile ▪ Dangerous
  • 4. Why do we write bad code ▪ Tight schedule ▪ Tired of project ▪ Get working now, clean up later (or never) ▪ Everybody does it!
  • 5. Why should we write clean code ▪ We spent most of our time reading rather than writing ▪ Bad code will cost you: ▪ Time ▪ Money ▪ Relationship ▪ Talent
  • 6. The boy scout rule ▪ Leave the campground cleaner than you found it.
  • 7. How do we write clean code
  • 8. Meaningful names ▪ Use Intention-Revealing Names ▪ Don’t be afraid of longer names, the name should say everything about it. ▪ Avoid abbreviation This is bad: protected $d; This is good: protected $elapsedTimeInDays; protected $daysSinceCreation; protected $daysSinceModification; protected $fileAgeInDays;
  • 9. ▪ Use pronounceable name This is bad: public $genymdhms; public $modymdhms; This is good: public $generationTimestamp; public $modificationTimestamp; ▪ Use one word per concept Be consistent. For example, don’t use get and fetch to do the same thing in different classes ▪ Use verbs for function names and nouns for classes and attributes
  • 10. Formatting ▪ Follow a single coding style ▪ There is no obvious "best" style. Just being consistent. ▪ Each line should be composed of a single expression. ▪ Each block should present a single thought. ▪ Blocks should be separated with a single, empty line. ▪ A line of the code should not exceed 80 characters ▪ Our eyes are more comfortable when reading tall and narrow columns of text ▪ Use indentation and alignment to improve the readability
  • 11. Functions ▪ The smaller the better ▪ A function should only do one thing ▪ No nested control structure ▪ Less arguments are better ▪ No side effects ▪ Avoid output arguments ▪ Don’t repeat yourself
  • 12. Hard to read Easy to understand
  • 13. Comments ▪ Don’t comment bad code, rewrite it ▪ If code is readable you don’t need comments ▪ Explain your intention in comments ▪ Warn of consequences in comments ▪ Emphasis important points in comments ▪ Always have you PHPDoc comments ▪ Noise comments are bad ▪ Never leave code commented
  • 14. ▪ The best comment is the code itself For example: // check if customer can buy products if ($customer->isActive() && $customer->getAge() > 65) is not as good as: if ($customer->canBuyProducts()) ▪ Avoid obvious comments ▪ Other kind of useful comments Legal comments, e.g. // Copyright (c) 2014 Magento Inc. Informative comments, e.g. // Returns an instance of a Customer object Purpose-explaining comments, e.g. return 1; // it is default value Warning comments, e.g. // very slow query, don’t use if you don’t need to TODO comments, e.g. // @TODO rewrite this query
  • 15. Reference ▪ Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin ▪ http://www.slideshare.net/mariosa ngiorgio/clean-code-and-code- smells ▪ http://www.slideshare.net/JandV/c lean-code-summary ▪ http://www.slideshare.net/josedasi lva/phplx