SlideShare a Scribd company logo
Clean Code
2
A Handbook of Agile Software Craftsmanship
Robert C. Martin
Note by waegaein@github.com
CH2 Meaningful Names
Variable Names
Function Names
Class Names
CH2 Meaningful Names
Names should
• tell you why it exists, what it does, and how it is used.
def sendtostore_packagestock0
→ def calculate_stock_with_notifying_store
CH2 Meaningful Names
Names should
• tell you why it exists, what it does, and how it is used.
• allow readers to understand difference without comment nor deduction.
def sendtostore_packagestock0
→ def calculate_stock_with_notifying_store
CH2 Meaningful Names
Names should
• tell you why it exists, what it does, and how it is used.
• allow readers to understand difference without comment nor deduction.
• include semantic words.
def sendtostore_packagestock0
def sendtostore_packagestock1
CH2 Meaningful Names
Names should
• tell you why it exists, what it does, and how it is used.
• allow readers to understand difference without comment nor deduction.
• include semantic words.
• include words that are technical or related to the problem domain.
def calculate_rate
→ def calculate_surcharge
CH2 Meaningful Names
Names should
• tell you why it exists, what it does, and how it is used.
• allow readers to understand difference without comment nor deduction.
• include semantic words.
• include words that are technical or related to the problem domain.
• have context from its scope.
Package_stock.package_stock_id
→ Package_stock.id
CH2 Meaningful Names
Names should
• tell you why it exists, what it does, and how it is used.
• allow readers to understand difference without comment nor deduction.
• include semantic words.
• include words that are technical or related to the problem domain.
• have context from its scope.
• consists of words.
daydelay
→ days_delayed
CH2 Meaningful Names
Names should not
• include obscure clues that may lead to false conclusions.
def create_invoice_with_assurance
→ def create_invoice_with_retry
CH2 Meaningful Names
Names should not
• include obscure clues that may lead to false conclusions.
• use inconsistent synonyms for a single concept.
(‘calculate_stock_with_notifying_store’ exists)
def send_mail_to_branch
→ def send_mail_to_store
CH2 Meaningful Names
Names should not
• include obscure clues that may lead to false conclusions.
• use inconsistent synonyms for a single concept.
• include syntactic encodings.
v_count
→ count
CH2 Meaningful Names
Names should not
• include obscure clues that may lead to false conclusions.
• use inconsistent synonyms for a single concept.
• include syntactic encodings.
• consists of over-abbreviated letters.
def get_psscharge
→ def get_package_stock_surchage
CH2 Meaningful Names
• Prefer clarity to smartness and entertainment.
_, _ = select.select([], [])
→ discarded, discarded = select.select(list(), list())
CH2 Meaningful Names
• Prefer clarity to smartness and entertainment.
• Class names are nouns or noun phrases.
class SlackNotify
→ class SlackNotification
CH2 Meaningful Names
• Prefer clarity to smartness and entertainment.
• Class names are nouns or noun phrases.
• Method names are verbs or verb phrases.
def surcharge_calculation
→ def calculate_surcharge
CH3 Functions
Functions should
• be as small as possible.
CH3 Functions
Functions should
• be as small as possible.
• have the indent level of one or two.
CH3 Functions
Functions should
• be as small as possible.
• have the indent level of one or two.
• do only one thing.
CH3 Functions
Functions should
• be as small as possible.
• have the indent level of one or two.
• do only one thing.
• include steps within one level of abstraction.
CH3 Functions
Functions should
• be as small as possible.
• have the indent level of one or two.
• do only one thing.
• include steps within one level of abstraction.
• have two arguments at maximum, taking advantage of argument objects/lists.
def send_mail_with_file(email_from, email_to, subject, html_content, attach_file_path,
attach_file_name, mime_type)
→ def send_mail_with_file(base_email, attachment)
CH3 Functions
Functions should not
• expose switch statements, which do multiple things inherently, to the high level.
CH3 Functions
Functions should not
• expose switch statements, which do multiple things inherently, to the high level.
• pass Boolean flag argument as it forces more than one behavior.
calculate_surcharge(is_promotion=False, …)
→ calculate_surcharge, calcuate_surcharge_for_promotion
CH3 Functions
Functions should not
• expose switch statements, which do multiple things inherently, to the high level.
• pass Boolean flag argument as it forces more than one behavior.
• transform input argument instead of using return value.
…
charge_list.sort()
…
return
…
charge_list_sorted = sorted(charge_list)
…
return charge_list_sorted
→
CH3 Functions
Functions should not
• expose switch statements, which do multiple things inherently, to the high level.
• pass Boolean flag argument as it forces more than one behavior.
• transform input argument instead of using return value.
• have side effects that are not implied by names.
CH3 Functions
Functions should not
• expose switch statements, which do multiple things inherently, to the high level.
• pass Boolean flag argument as it forces more than one behavior.
• transform input argument instead of using return value.
• have side effects that are not implied by names.
• perform command and query at the same time.
• perform action and error handling at the same time.
CH3 Functions
Functions should not
• expose switch statements, which do multiple things inherently, to the high level.
• pass Boolean flag argument as it forces more than one behavior.
• transform input argument instead of using return value.
• have side effects that are not implied by names.
• perform command and query at the same time.
• perform action and error handling at the same time.
• have multiple entries or exits.
CH3 Functions

More Related Content

What's hot

Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
Ramasubbu .P
 
Hw1 rubycalisthenics
Hw1 rubycalisthenicsHw1 rubycalisthenics
Hw1 rubycalisthenicsshelton88
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl language
Masahiro Honma
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
sana mateen
 
Regex posix
Regex posixRegex posix
Regex posix
sana mateen
 
Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introduction
Prof. Wim Van Criekinge
 

What's hot (6)

Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
 
Hw1 rubycalisthenics
Hw1 rubycalisthenicsHw1 rubycalisthenics
Hw1 rubycalisthenics
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl language
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Regex posix
Regex posixRegex posix
Regex posix
 
Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introduction
 

Similar to Clean Code - 2

Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
ZubairAli256321
 
Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Codinginspector_fegter
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
Chiyoung Song
 
Calc i derivatives
Calc i derivativesCalc i derivatives
Calc i derivatives
Viorica Tonu
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
Metin Ogurlu
 
Clean Code
Clean CodeClean Code
Clean Code
Dmytro Turskyi
 
Unison Language - Contact
Unison Language - ContactUnison Language - Contact
Unison Language - Contact
Philip Schwarz
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
Yoeung Vibol
 
DIG1108C Lesson 5 Fall 2014
DIG1108C Lesson 5 Fall 2014DIG1108C Lesson 5 Fall 2014
DIG1108C Lesson 5 Fall 2014
David Wolfpaw
 
Apple Swift API Design Guideline
Apple Swift API Design GuidelineApple Swift API Design Guideline
Apple Swift API Design Guideline
Chihyang Li
 
Introduction to Perl and BioPerl
Introduction to Perl and BioPerlIntroduction to Perl and BioPerl
Introduction to Perl and BioPerl
Bioinformatics and Computational Biosciences Branch
 
DIG1108C Lesson 2 Fall 2014
DIG1108C Lesson 2 Fall 2014DIG1108C Lesson 2 Fall 2014
DIG1108C Lesson 2 Fall 2014David Wolfpaw
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptxCLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
JEEVANANTHAMG6
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
Tushar Pal
 

Similar to Clean Code - 2 (20)

Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Coding
 
Week2
Week2Week2
Week2
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
Calc i derivatives
Calc i derivativesCalc i derivatives
Calc i derivatives
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Clean Code
Clean CodeClean Code
Clean Code
 
Unison Language - Contact
Unison Language - ContactUnison Language - Contact
Unison Language - Contact
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
DIG1108C Lesson 5 Fall 2014
DIG1108C Lesson 5 Fall 2014DIG1108C Lesson 5 Fall 2014
DIG1108C Lesson 5 Fall 2014
 
Apple Swift API Design Guideline
Apple Swift API Design GuidelineApple Swift API Design Guideline
Apple Swift API Design Guideline
 
Introduction to Perl and BioPerl
Introduction to Perl and BioPerlIntroduction to Perl and BioPerl
Introduction to Perl and BioPerl
 
DIG1108C Lesson 2 Fall 2014
DIG1108C Lesson 2 Fall 2014DIG1108C Lesson 2 Fall 2014
DIG1108C Lesson 2 Fall 2014
 
CLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptxCLEAN CODING AND DEVOPS Final.pptx
CLEAN CODING AND DEVOPS Final.pptx
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 

More from Don Kim

Clean Code - 5
Clean Code - 5Clean Code - 5
Clean Code - 5
Don Kim
 
Clean Code - 4
Clean Code - 4Clean Code - 4
Clean Code - 4
Don Kim
 
Clean Code - 3
Clean Code - 3Clean Code - 3
Clean Code - 3
Don Kim
 
Clean Code - 1
Clean Code - 1Clean Code - 1
Clean Code - 1
Don Kim
 
Design and Analyze Secure Networked Systems - 7
Design and Analyze Secure Networked Systems - 7Design and Analyze Secure Networked Systems - 7
Design and Analyze Secure Networked Systems - 7
Don Kim
 
Design and Analyze Secure Networked Systems - 6
Design and Analyze Secure Networked Systems - 6Design and Analyze Secure Networked Systems - 6
Design and Analyze Secure Networked Systems - 6
Don Kim
 
Design and Analyze Secure Networked Systems - 5
Design and Analyze Secure Networked Systems - 5Design and Analyze Secure Networked Systems - 5
Design and Analyze Secure Networked Systems - 5
Don Kim
 
Design and Analyze Secure Networked Systems - 4
Design and Analyze Secure Networked Systems - 4Design and Analyze Secure Networked Systems - 4
Design and Analyze Secure Networked Systems - 4
Don Kim
 
Design and Analyze Secure Networked Systems - 3
Design and Analyze Secure Networked Systems - 3Design and Analyze Secure Networked Systems - 3
Design and Analyze Secure Networked Systems - 3
Don Kim
 
Design and Analyze Secure Networked Systems - 2
Design and Analyze Secure Networked Systems - 2Design and Analyze Secure Networked Systems - 2
Design and Analyze Secure Networked Systems - 2
Don Kim
 
Design and Analyze Secure Networked Systems - 1
Design and Analyze Secure Networked Systems - 1Design and Analyze Secure Networked Systems - 1
Design and Analyze Secure Networked Systems - 1
Don Kim
 

More from Don Kim (11)

Clean Code - 5
Clean Code - 5Clean Code - 5
Clean Code - 5
 
Clean Code - 4
Clean Code - 4Clean Code - 4
Clean Code - 4
 
Clean Code - 3
Clean Code - 3Clean Code - 3
Clean Code - 3
 
Clean Code - 1
Clean Code - 1Clean Code - 1
Clean Code - 1
 
Design and Analyze Secure Networked Systems - 7
Design and Analyze Secure Networked Systems - 7Design and Analyze Secure Networked Systems - 7
Design and Analyze Secure Networked Systems - 7
 
Design and Analyze Secure Networked Systems - 6
Design and Analyze Secure Networked Systems - 6Design and Analyze Secure Networked Systems - 6
Design and Analyze Secure Networked Systems - 6
 
Design and Analyze Secure Networked Systems - 5
Design and Analyze Secure Networked Systems - 5Design and Analyze Secure Networked Systems - 5
Design and Analyze Secure Networked Systems - 5
 
Design and Analyze Secure Networked Systems - 4
Design and Analyze Secure Networked Systems - 4Design and Analyze Secure Networked Systems - 4
Design and Analyze Secure Networked Systems - 4
 
Design and Analyze Secure Networked Systems - 3
Design and Analyze Secure Networked Systems - 3Design and Analyze Secure Networked Systems - 3
Design and Analyze Secure Networked Systems - 3
 
Design and Analyze Secure Networked Systems - 2
Design and Analyze Secure Networked Systems - 2Design and Analyze Secure Networked Systems - 2
Design and Analyze Secure Networked Systems - 2
 
Design and Analyze Secure Networked Systems - 1
Design and Analyze Secure Networked Systems - 1Design and Analyze Secure Networked Systems - 1
Design and Analyze Secure Networked Systems - 1
 

Recently uploaded

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
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
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
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
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
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
 
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
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
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
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
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
 
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
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 

Recently uploaded (20)

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
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
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
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
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
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
 
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
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
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 ...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
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
 
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
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 

Clean Code - 2

  • 1. Clean Code 2 A Handbook of Agile Software Craftsmanship Robert C. Martin Note by waegaein@github.com
  • 2. CH2 Meaningful Names Variable Names Function Names Class Names
  • 3. CH2 Meaningful Names Names should • tell you why it exists, what it does, and how it is used. def sendtostore_packagestock0 → def calculate_stock_with_notifying_store
  • 4. CH2 Meaningful Names Names should • tell you why it exists, what it does, and how it is used. • allow readers to understand difference without comment nor deduction. def sendtostore_packagestock0 → def calculate_stock_with_notifying_store
  • 5. CH2 Meaningful Names Names should • tell you why it exists, what it does, and how it is used. • allow readers to understand difference without comment nor deduction. • include semantic words. def sendtostore_packagestock0 def sendtostore_packagestock1
  • 6. CH2 Meaningful Names Names should • tell you why it exists, what it does, and how it is used. • allow readers to understand difference without comment nor deduction. • include semantic words. • include words that are technical or related to the problem domain. def calculate_rate → def calculate_surcharge
  • 7. CH2 Meaningful Names Names should • tell you why it exists, what it does, and how it is used. • allow readers to understand difference without comment nor deduction. • include semantic words. • include words that are technical or related to the problem domain. • have context from its scope. Package_stock.package_stock_id → Package_stock.id
  • 8. CH2 Meaningful Names Names should • tell you why it exists, what it does, and how it is used. • allow readers to understand difference without comment nor deduction. • include semantic words. • include words that are technical or related to the problem domain. • have context from its scope. • consists of words. daydelay → days_delayed
  • 9. CH2 Meaningful Names Names should not • include obscure clues that may lead to false conclusions. def create_invoice_with_assurance → def create_invoice_with_retry
  • 10. CH2 Meaningful Names Names should not • include obscure clues that may lead to false conclusions. • use inconsistent synonyms for a single concept. (‘calculate_stock_with_notifying_store’ exists) def send_mail_to_branch → def send_mail_to_store
  • 11. CH2 Meaningful Names Names should not • include obscure clues that may lead to false conclusions. • use inconsistent synonyms for a single concept. • include syntactic encodings. v_count → count
  • 12. CH2 Meaningful Names Names should not • include obscure clues that may lead to false conclusions. • use inconsistent synonyms for a single concept. • include syntactic encodings. • consists of over-abbreviated letters. def get_psscharge → def get_package_stock_surchage
  • 13. CH2 Meaningful Names • Prefer clarity to smartness and entertainment. _, _ = select.select([], []) → discarded, discarded = select.select(list(), list())
  • 14. CH2 Meaningful Names • Prefer clarity to smartness and entertainment. • Class names are nouns or noun phrases. class SlackNotify → class SlackNotification
  • 15. CH2 Meaningful Names • Prefer clarity to smartness and entertainment. • Class names are nouns or noun phrases. • Method names are verbs or verb phrases. def surcharge_calculation → def calculate_surcharge
  • 16. CH3 Functions Functions should • be as small as possible.
  • 17. CH3 Functions Functions should • be as small as possible. • have the indent level of one or two.
  • 18. CH3 Functions Functions should • be as small as possible. • have the indent level of one or two. • do only one thing.
  • 19. CH3 Functions Functions should • be as small as possible. • have the indent level of one or two. • do only one thing. • include steps within one level of abstraction.
  • 20. CH3 Functions Functions should • be as small as possible. • have the indent level of one or two. • do only one thing. • include steps within one level of abstraction. • have two arguments at maximum, taking advantage of argument objects/lists. def send_mail_with_file(email_from, email_to, subject, html_content, attach_file_path, attach_file_name, mime_type) → def send_mail_with_file(base_email, attachment)
  • 21. CH3 Functions Functions should not • expose switch statements, which do multiple things inherently, to the high level.
  • 22. CH3 Functions Functions should not • expose switch statements, which do multiple things inherently, to the high level. • pass Boolean flag argument as it forces more than one behavior. calculate_surcharge(is_promotion=False, …) → calculate_surcharge, calcuate_surcharge_for_promotion
  • 23. CH3 Functions Functions should not • expose switch statements, which do multiple things inherently, to the high level. • pass Boolean flag argument as it forces more than one behavior. • transform input argument instead of using return value. … charge_list.sort() … return … charge_list_sorted = sorted(charge_list) … return charge_list_sorted →
  • 24. CH3 Functions Functions should not • expose switch statements, which do multiple things inherently, to the high level. • pass Boolean flag argument as it forces more than one behavior. • transform input argument instead of using return value. • have side effects that are not implied by names.
  • 25. CH3 Functions Functions should not • expose switch statements, which do multiple things inherently, to the high level. • pass Boolean flag argument as it forces more than one behavior. • transform input argument instead of using return value. • have side effects that are not implied by names. • perform command and query at the same time. • perform action and error handling at the same time.
  • 26. CH3 Functions Functions should not • expose switch statements, which do multiple things inherently, to the high level. • pass Boolean flag argument as it forces more than one behavior. • transform input argument instead of using return value. • have side effects that are not implied by names. • perform command and query at the same time. • perform action and error handling at the same time. • have multiple entries or exits.