SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Coding standards
Coding standardsCoding standards
Coding standards
Mark Reynolds
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 
Clean Code
Clean CodeClean Code
Clean Code
Dmytro Turskyi
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
Angel Garcia Olloqui
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
systemcrashed
 
Clean code slide
Clean code slideClean code slide
Clean code slide
Anh Huan Miu
 
Coding standards
Coding standardsCoding standards
Coding standards
Mimoh Ojha
 
Clean Code
Clean CodeClean Code
Clean Code
Victor Rentea
 
Clean code
Clean code Clean code
Clean code
Achintya Kumar
 
Clean code
Clean codeClean code
Clean code
Henrique Smoco
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
YeurDreamin'
 
Clean code
Clean codeClean code
Clean code
Jean Carlo Machado
 
Clean code
Clean codeClean code
Clean code
Mahmoud Zizo
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
Richard Dingwall
 
Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean Code
CleanestCode
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
Badoo
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
Dmytro Turskyi
 
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
 
Code Smells
Code SmellsCode Smells
Code Smells
Mrinal Bhattacaharya
 
Code smells and remedies
Code smells and remediesCode smells and remedies
Code smells and remedies
Md.Mojibul Hoque
 

Viewers also liked (17)

Danny McGourty CV4
Danny McGourty CV4Danny McGourty CV4
Danny McGourty CV4
Danny McGourty
 
Landa brands ch1_rev
Landa brands ch1_revLanda brands ch1_rev
Landa brands ch1_rev
Marcio Domingues
 
Horari alumnes 6è 15 16
Horari alumnes 6è 15 16Horari alumnes 6è 15 16
Horari alumnes 6è 15 16
EscolaGoya
 
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
Rosilene Martins
 
Carnestoltes
CarnestoltesCarnestoltes
Carnestoltes
EscolaGoya
 
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
ESCOLA SEGIMON COMAS Sant Quirze de Besora
 
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
Laerte 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 2012
David Feighan
 
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
gloriainesmaipore
 
Publish Subscriber messaging pattern
Publish Subscriber messaging patternPublish Subscriber messaging pattern
Publish Subscriber messaging pattern
Shirish Bari
 
A Blended Communication Approach
A Blended Communication ApproachA Blended Communication Approach
A Blended Communication Approach
guestf57c39
 
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
 
Choque de civilizações?
Choque de civilizações?Choque de civilizações?
Choque de civilizações?
Maria Julia Sant'Ana
 
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
Steve 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 trabalho
Lemon 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 16
pompeufabramollerussa
 
Llibret informatiu 2015 16
Llibret informatiu 2015 16Llibret informatiu 2015 16
Llibret informatiu 2015 16
pompeufabramollerussa
 
Horari alumnes 6è 15 16
Horari alumnes 6è 15 16Horari alumnes 6è 15 16
Horari alumnes 6è 15 16
EscolaGoya
 
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
Rosilene 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 juramentada
Laerte 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 2012
David Feighan
 
Publish Subscriber messaging pattern
Publish Subscriber messaging patternPublish Subscriber messaging pattern
Publish Subscriber messaging pattern
Shirish Bari
 
A Blended Communication Approach
A Blended Communication ApproachA Blended Communication Approach
A Blended Communication Approach
guestf57c39
 
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 Strategy
Steve 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 trabalho
Lemon 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 16
pompeufabramollerussa
 
Ad

Similar to Writing Clean Code (Recommendations by Robert Martin) (20)

Clean code
Clean codeClean code
Clean code
Simon Sönnby
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
Metin 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.ppt
VinayakHospet1
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approach
Enrico Da Ros
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven Smith
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
Juggernaut Liu
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
Steven Smith
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Amr Abd El Latief
 
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
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
Bhavin Gandhi
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven 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 Interfaces
Jitendra Zaa
 
Clean Code
Clean CodeClean Code
Clean Code
swaraj Patil
 
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
Rohan Rasane
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
Alfred Jett Grandeza
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
Meilan Ou
 
Bdd with m spec
Bdd with m specBdd with m spec
Bdd with m spec
Pavneet Singh Saund
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
Metin 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.ppt
VinayakHospet1
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approach
Enrico Da Ros
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven Smith
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
Juggernaut Liu
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
Steven 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
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
Bhavin Gandhi
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven 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 Interfaces
Jitendra 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 2018
Rohan Rasane
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
Meilan Ou
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
 
Ad

Recently uploaded (20)

EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 

Writing Clean Code (Recommendations by Robert 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