SlideShare a Scribd company logo
1 of 15
Clean Code Best Practices
…….by Robert C. Martin
Background
• Studied
• Clean Code: A Handbook of Agile Software
Craftsmanship
• Presentation provide the summary of clean code best
practices given by Robert C martin
Meaningful Names
• Naming Rules
• Avoid mental mapping when naming methods, classes or variables
• Classes and objects should have noun or noun phrase names like
Customer, WikiPage, Account, and AddressParser etc
• Methods should have verb or verb phrase names like postPayment,
deletePage, or save .
• Accessors, mutators and predicates should be named for their value
and prefixed with get, set, and is according to the javabean standard.
• Don’t Add Gratuitous Context
• If your application Name is GSD then do not prefix GSD to class names like
GSDMailing , GSDAccountProcessing .
Meaningful Names
• Use Pronounceable Names
• The length of a name should correspond to the size of its scope
• Variables i , j could be used as loop variables
• Avoid Disinformation
• Use Intention-Revealing Names
• The name of a variable, function, or class should answer
Why it exists ? What it does ? and how it is used ?
• int d; vs int elapsedTimeInDays or int daysSinceCreation
• Variables named as hp, aix and sco should be avoided
Functions
• Should Be small
• Handle One Abstraction per function
• Function should do One Thing ,they should do it well , they should
do it only
• Prefer exceptions than Returning error codes
• Remove code duplication
• Function should not produce side effects
Comments
• Should be used when required like
• Legal terms and conditions
• Provides information about the intent
• Clarification
• Warning of consequences
• TODO comments
• Java Docs in public API
Comments
• Following comments would be considered as Bad
comments if they are
• Redundant
• Misleading
• Java docs in non public code
• Journal
• Noise
• Closing brace
• Dead code
Formatting
• Team should decide the formatting/indentation strategy and
everyone in the team should follow this strategy
• Strategy could be about
• Vertical formatting . Recommended No. of Lines per Java source File
• Vertical Openness between concepts
• Variable declaration – Local variables and instance variables
• Dependant functions should be just below the caller
• Horizontal formatting – line should be less than 120 chars
• Indentation - should not break indentation for small if or loop
statements
Objects and Data Structures
• Data/Object Anti-Symmetry
• Objects hide their data behind abstractions and expose
functions that operate on that data
• Data structure expose their data and have no meaningful
functions.
• Sometimes you really do want simple data structures with
procedures operating on them. Data Structures like Value
Objects, Beans , DTO’s recommends having setters and
getters
• Data structures Should not contain business rule methods
Objects and Data Structures
• The Law of Demeter
• module should not know about the innards of the objects it manipulates.
• The Law of Demeter says that a method f of a class C should only call the methods
of these:
• C
• An object created by f
• An object passed as an argument to f
• An object held in an instance variable of C
• final String outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath(); // This is
violation of law of Demeter
• Demeter Law does not apply to Data structures because by nature Data Structure
expose their internals
Error Handling
• Use Exceptions Rather Than Error Codes
• Create informative error messages and pass them along
with your exceptions
• Don’t Pass Null value to function and don’t return null
• If your API expected to return Null then this condition needs
to be handled in our code
• We can write robust clean code if we see error handling as
a separate concern
Boundaries
• Exploring and Learning Boundaries
• Learning tests could be very helpful for this
• boundary should be supported by a set of outbound tests
• manage third-party boundaries by having very few places in
the code that refer to them
Unit Tests
• Unit tests keeps our code flexible, maintainable and reusable. Confidence
of change increases when there are more number of tests.
• The BUILD-OPERATE-CHECK pattern should be used for Unit tests
• The Three Laws of TDD
1. You may not write production code until you have written a failing unit test
2. You may not write more of a unit test than is sufficient to fail, and not compiling is
failing.
3. You may not write more production code than is sufficient to pass the currently failing
test
• Single Concept per Test Vs One Assert per Tests
• Tests Should be Fast ,Independent ,Repeatable ,Self-validating and Timely –
F.I.R.S.T
Classes
• Classes should Be small
• Single Responsibility Principal – There should be only one
reason to change the class
• Open Close Principal – Class should be Open for
extension and close for modification
• Classes should have High Cohesion and Loose Coupling
References
• Clean Code book by Robert C Martin

More Related Content

What's hot

無瑕的程式碼 Clean Code 心得分享
無瑕的程式碼 Clean Code 心得分享無瑕的程式碼 Clean Code 心得分享
無瑕的程式碼 Clean Code 心得分享Win Yu
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionKent Huang
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Namenahid035
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable codeGeshan Manandhar
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Asim Rais Siddiqui
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignVictor Rentea
 
Rust system programming language
Rust system programming languageRust system programming language
Rust system programming languagerobin_sy
 

What's hot (20)

Clean code
Clean codeClean code
Clean code
 
Clean code
Clean codeClean code
Clean code
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
無瑕的程式碼 Clean Code 心得分享
無瑕的程式碼 Clean Code 心得分享無瑕的程式碼 Clean Code 心得分享
無瑕的程式碼 Clean Code 心得分享
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
 
Clean Code
Clean CodeClean Code
Clean Code
 
Chapter17 of clean code
Chapter17 of clean codeChapter17 of clean code
Chapter17 of clean code
 
Clean code
Clean codeClean code
Clean code
 
Coding standard
Coding standardCoding standard
Coding standard
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Name
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
Clean code
Clean codeClean code
Clean code
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Clean Code
Clean CodeClean Code
Clean Code
 
Rust system programming language
Rust system programming languageRust system programming language
Rust system programming language
 

Viewers also liked

Horari alumnes 6è 15 16
Horari alumnes 6è 15 16Horari alumnes 6è 15 16
Horari alumnes 6è 15 16EscolaGoya
 
Multimodalidades como Técnica de Aprendizado em Empreendedorismo
Multimodalidades como Técnica de Aprendizado em EmpreendedorismoMultimodalidades como Técnica de Aprendizado em Empreendedorismo
Multimodalidades como Técnica de Aprendizado em EmpreendedorismoRosilene Martins
 
Quais são os documentos que exigem tradução juramentada
Quais são os documentos que exigem tradução juramentadaQuais são os documentos que exigem tradução juramentada
Quais são os documentos que exigem tradução juramentadaLaerte J Silva
 
Australian Independent School Teacher Librarian Conference 2012
Australian Independent School Teacher Librarian Conference 2012Australian Independent School Teacher Librarian Conference 2012
Australian Independent School Teacher Librarian Conference 2012David Feighan
 
Publish Subscriber messaging pattern
Publish Subscriber messaging patternPublish Subscriber messaging pattern
Publish Subscriber messaging patternShirish Bari
 
A Blended Communication Approach
A Blended Communication ApproachA Blended Communication Approach
A Blended Communication Approachguestf57c39
 
HP - A transformacao do posto de trabalho (vp)
HP - A transformacao do posto de trabalho (vp)HP - A transformacao do posto de trabalho (vp)
HP - A transformacao do posto de trabalho (vp)Pedro Coelho
 
Why You Should Use a Mobile-First Strategy
Why You Should Use a Mobile-First StrategyWhy You Should Use a Mobile-First Strategy
Why You Should Use a Mobile-First StrategySteve Bain
 
Fdd feature driven development (slide ) do trabalho
Fdd   feature driven development (slide ) do trabalhoFdd   feature driven development (slide ) do trabalho
Fdd feature driven development (slide ) do trabalhoLemon Lopes Leite
 
Llibres escola pompeu fabra curs 15 16
Llibres escola pompeu fabra curs 15 16Llibres escola pompeu fabra curs 15 16
Llibres escola pompeu fabra curs 15 16pompeufabramollerussa
 

Viewers also liked (17)

Danny McGourty CV4
Danny McGourty CV4Danny McGourty CV4
Danny McGourty CV4
 
Landa brands ch1_rev
Landa brands ch1_revLanda brands ch1_rev
Landa brands ch1_rev
 
Horari alumnes 6è 15 16
Horari alumnes 6è 15 16Horari alumnes 6è 15 16
Horari alumnes 6è 15 16
 
Multimodalidades como Técnica de Aprendizado em Empreendedorismo
Multimodalidades como Técnica de Aprendizado em EmpreendedorismoMultimodalidades como Técnica de Aprendizado em Empreendedorismo
Multimodalidades como Técnica de Aprendizado em Empreendedorismo
 
Carnestoltes
CarnestoltesCarnestoltes
Carnestoltes
 
Informació final constitució del consell escolar 13 12 2016.docx
Informació final constitució del consell escolar 13 12 2016.docxInformació final constitució del consell escolar 13 12 2016.docx
Informació final constitució del consell escolar 13 12 2016.docx
 
Quais são os documentos que exigem tradução juramentada
Quais são os documentos que exigem tradução juramentadaQuais são os documentos que exigem tradução juramentada
Quais são os documentos que exigem tradução juramentada
 
Australian Independent School Teacher Librarian Conference 2012
Australian Independent School Teacher Librarian Conference 2012Australian Independent School Teacher Librarian Conference 2012
Australian Independent School Teacher Librarian Conference 2012
 
Notas 2º período de 6 06
Notas 2º período de 6 06Notas 2º período de 6 06
Notas 2º período de 6 06
 
Publish Subscriber messaging pattern
Publish Subscriber messaging patternPublish Subscriber messaging pattern
Publish Subscriber messaging pattern
 
A Blended Communication Approach
A Blended Communication ApproachA Blended Communication Approach
A Blended Communication Approach
 
HP - A transformacao do posto de trabalho (vp)
HP - A transformacao do posto de trabalho (vp)HP - A transformacao do posto de trabalho (vp)
HP - A transformacao do posto de trabalho (vp)
 
Choque de civilizações?
Choque de civilizações?Choque de civilizações?
Choque de civilizações?
 
Why You Should Use a Mobile-First Strategy
Why You Should Use a Mobile-First StrategyWhy You Should Use a Mobile-First Strategy
Why You Should Use a Mobile-First Strategy
 
Fdd feature driven development (slide ) do trabalho
Fdd   feature driven development (slide ) do trabalhoFdd   feature driven development (slide ) do trabalho
Fdd feature driven development (slide ) do trabalho
 
Llibres escola pompeu fabra curs 15 16
Llibres escola pompeu fabra curs 15 16Llibres escola pompeu fabra curs 15 16
Llibres escola pompeu fabra curs 15 16
 
Llibret informatiu 2015 16
Llibret informatiu 2015 16Llibret informatiu 2015 16
Llibret informatiu 2015 16
 

Similar to Clean Code Best Practices Summary by Robert C. Martin

Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptVinayakHospet1
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approachEnrico Da Ros
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programmingJuggernaut Liu
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing SoftwareSteven Smith
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...AgileNetwork
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and InterfacesEpisode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and InterfacesJitendra Zaa
 
Integration strategies best practices- Mulesoft meetup April 2018
Integration strategies   best practices- Mulesoft meetup April 2018Integration strategies   best practices- Mulesoft meetup April 2018
Integration strategies best practices- Mulesoft meetup April 2018Rohan Rasane
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesteach4uin
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practicesBill Buchan
 
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptxAlgorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptxRobertCarreonBula
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 

Similar to Clean Code Best Practices Summary by Robert C. Martin (20)

Clean code
Clean codeClean code
Clean code
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approach
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and InterfacesEpisode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
 
Integration strategies best practices- Mulesoft meetup April 2018
Integration strategies   best practices- Mulesoft meetup April 2018Integration strategies   best practices- Mulesoft meetup April 2018
Integration strategies best practices- Mulesoft meetup April 2018
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Bdd with m spec
Bdd with m specBdd with m spec
Bdd with m spec
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Code reviews
Code reviewsCode reviews
Code reviews
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
 
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptxAlgorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
Algorithms-Flowcharts-Data-Types-and-Pseudocodes.pptx
 
Code reviews
Code reviewsCode reviews
Code reviews
 

Recently uploaded

2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 

Recently uploaded (20)

2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 

Clean Code Best Practices Summary by Robert C. Martin

  • 1. Clean Code Best Practices …….by Robert C. Martin
  • 2. Background • Studied • Clean Code: A Handbook of Agile Software Craftsmanship • Presentation provide the summary of clean code best practices given by Robert C martin
  • 3. Meaningful Names • Naming Rules • Avoid mental mapping when naming methods, classes or variables • Classes and objects should have noun or noun phrase names like Customer, WikiPage, Account, and AddressParser etc • Methods should have verb or verb phrase names like postPayment, deletePage, or save . • Accessors, mutators and predicates should be named for their value and prefixed with get, set, and is according to the javabean standard. • Don’t Add Gratuitous Context • If your application Name is GSD then do not prefix GSD to class names like GSDMailing , GSDAccountProcessing .
  • 4. Meaningful Names • Use Pronounceable Names • The length of a name should correspond to the size of its scope • Variables i , j could be used as loop variables • Avoid Disinformation • Use Intention-Revealing Names • The name of a variable, function, or class should answer Why it exists ? What it does ? and how it is used ? • int d; vs int elapsedTimeInDays or int daysSinceCreation • Variables named as hp, aix and sco should be avoided
  • 5. Functions • Should Be small • Handle One Abstraction per function • Function should do One Thing ,they should do it well , they should do it only • Prefer exceptions than Returning error codes • Remove code duplication • Function should not produce side effects
  • 6. Comments • Should be used when required like • Legal terms and conditions • Provides information about the intent • Clarification • Warning of consequences • TODO comments • Java Docs in public API
  • 7. Comments • Following comments would be considered as Bad comments if they are • Redundant • Misleading • Java docs in non public code • Journal • Noise • Closing brace • Dead code
  • 8. Formatting • Team should decide the formatting/indentation strategy and everyone in the team should follow this strategy • Strategy could be about • Vertical formatting . Recommended No. of Lines per Java source File • Vertical Openness between concepts • Variable declaration – Local variables and instance variables • Dependant functions should be just below the caller • Horizontal formatting – line should be less than 120 chars • Indentation - should not break indentation for small if or loop statements
  • 9. Objects and Data Structures • Data/Object Anti-Symmetry • Objects hide their data behind abstractions and expose functions that operate on that data • Data structure expose their data and have no meaningful functions. • Sometimes you really do want simple data structures with procedures operating on them. Data Structures like Value Objects, Beans , DTO’s recommends having setters and getters • Data structures Should not contain business rule methods
  • 10. Objects and Data Structures • The Law of Demeter • module should not know about the innards of the objects it manipulates. • The Law of Demeter says that a method f of a class C should only call the methods of these: • C • An object created by f • An object passed as an argument to f • An object held in an instance variable of C • final String outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath(); // This is violation of law of Demeter • Demeter Law does not apply to Data structures because by nature Data Structure expose their internals
  • 11. Error Handling • Use Exceptions Rather Than Error Codes • Create informative error messages and pass them along with your exceptions • Don’t Pass Null value to function and don’t return null • If your API expected to return Null then this condition needs to be handled in our code • We can write robust clean code if we see error handling as a separate concern
  • 12. Boundaries • Exploring and Learning Boundaries • Learning tests could be very helpful for this • boundary should be supported by a set of outbound tests • manage third-party boundaries by having very few places in the code that refer to them
  • 13. Unit Tests • Unit tests keeps our code flexible, maintainable and reusable. Confidence of change increases when there are more number of tests. • The BUILD-OPERATE-CHECK pattern should be used for Unit tests • The Three Laws of TDD 1. You may not write production code until you have written a failing unit test 2. You may not write more of a unit test than is sufficient to fail, and not compiling is failing. 3. You may not write more production code than is sufficient to pass the currently failing test • Single Concept per Test Vs One Assert per Tests • Tests Should be Fast ,Independent ,Repeatable ,Self-validating and Timely – F.I.R.S.T
  • 14. Classes • Classes should Be small • Single Responsibility Principal – There should be only one reason to change the class • Open Close Principal – Class should be Open for extension and close for modification • Classes should have High Cohesion and Loose Coupling
  • 15. References • Clean Code book by Robert C Martin