SlideShare a Scribd company logo
1 of 11
www.extentia.com | Confidential
WRITING A ‘CLEAN’
CODE
Simple Tips for Young Developers
www.extentia.com | Confidential
What is a Clean Code?
• A code that can be easily read,
understood, maintained, and extended
• Indicates the maintainability and
extensibility of the code for years (if not
decades!)
• Ideally, sustainable from the people who
originally wrote it to the developers who
joined in later
www.extentia.com | Confidential
The Need for Clean Codes
Addressing issues with the application of SOLID principles or some of the
other design patterns:
• Difficult to apply in practical situations while under pressure
• Subject to multiple interpretations and can be confusing
• Understanding them requires a certain level of experience
• Classroom teaching, alone, may not be sufficient
www.extentia.com | Confidential
5 Simple Tips For Writing a Clean
Code
www.extentia.com | Confidential
Think Before You Type!
• Every line of code is a potential cause for a
bug
• Hence, you must think very deeply before:
• Naming variables
• Organizing code into blocks, functions, etc.
• Think from the perspective of another
developer
• So, multiple developers can maintain the code
for years
www.extentia.com | Confidential
Avoid ‘Ladder-to-Hell’ Patterns
• ‘Ladder-to-Hell’ pattern
• One of the most used programming patterns;
resembles the code given on the right
• Occurs when lots of nested if-else, for and while
loops are used
• Makes the code untestable and un-maintainable
• Can be avoided by
• Decomposing the blocks to functions till the
leaf(ves) has just ONE ‘if-else’ block
• Using Sonar or other static analysis tools to detect
and eliminate them
www.extentia.com | Confidential
Write Computational Logic as ‘Pure’ Functions
• Do NOT mix I/O operations with
computational logic
• I/O operations make computational logic
difficult to test using automation
• Testing such a function requires mocking
the DB and building other scaffolding
• Code on the right is an example of how
it should be written
• To make the processResultSet() function
testable using automated unit tests
www.extentia.com | Confidential
Keep the Length of Functions to Less Than 35
• Programming is about decomposing
problems into smaller problems and then
composing them back into a whole
• Smaller functions are easier to understand
• Long functions require scrolling up and down
continuously, causing mental and physical
strain
• A function should be visible on a single
screen in the smallest device
www.extentia.com | Confidential
Keep the Conditionals at Less Than 7
• Restrict the cyclomatic complexity (if-
statements, termination of loops, etc.)
to less than 7, because
• Human short-term memory holds up to 7
pieces of information at once
• As the number increases, our ability to
comprehend reduces
• Lesser cyclomatic complexity leads to a
lesser number of unit tests
www.extentia.com | Confidential
www.extentia.com | Confidential
Thank You!
Write to us at inquiries.extentia.com to learn more!
More about Extentia’s offerings at https://www.extentia.com

More Related Content

More from Extentia Information Technology

The Global Fintech Trends of 2021-2022 and Its Undercurrents
The Global Fintech Trends of 2021-2022 and Its UndercurrentsThe Global Fintech Trends of 2021-2022 and Its Undercurrents
The Global Fintech Trends of 2021-2022 and Its UndercurrentsExtentia Information Technology
 
Driving Digital Transformation with SAP Cloud Integration
Driving Digital Transformation with SAP Cloud IntegrationDriving Digital Transformation with SAP Cloud Integration
Driving Digital Transformation with SAP Cloud IntegrationExtentia Information Technology
 
Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!
Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!
Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!Extentia Information Technology
 
Solving Business Problems with Machine Learning in SAP Analytics Cloud
Solving Business Problems with Machine Learning in SAP Analytics CloudSolving Business Problems with Machine Learning in SAP Analytics Cloud
Solving Business Problems with Machine Learning in SAP Analytics CloudExtentia Information Technology
 

More from Extentia Information Technology (20)

Microsoft Azure over other clouds
Microsoft Azure over other cloudsMicrosoft Azure over other clouds
Microsoft Azure over other clouds
 
Get Started with Microsoft Azure
Get Started with Microsoft AzureGet Started with Microsoft Azure
Get Started with Microsoft Azure
 
Understanding Microsoft Azure
Understanding Microsoft AzureUnderstanding Microsoft Azure
Understanding Microsoft Azure
 
Modern Technologies Disrupting the Banking Sector
Modern Technologies Disrupting the Banking SectorModern Technologies Disrupting the Banking Sector
Modern Technologies Disrupting the Banking Sector
 
The Global Fintech Trends of 2021-2022 and Its Undercurrents
The Global Fintech Trends of 2021-2022 and Its UndercurrentsThe Global Fintech Trends of 2021-2022 and Its Undercurrents
The Global Fintech Trends of 2021-2022 and Its Undercurrents
 
Fintech Revolution During COVID-19 Pandemic
Fintech Revolution During COVID-19 PandemicFintech Revolution During COVID-19 Pandemic
Fintech Revolution During COVID-19 Pandemic
 
The Evolution of Fintech Space
The Evolution of Fintech SpaceThe Evolution of Fintech Space
The Evolution of Fintech Space
 
The Desirability and Feasibility of a Design.pptx
The Desirability and Feasibility of a Design.pptxThe Desirability and Feasibility of a Design.pptx
The Desirability and Feasibility of a Design.pptx
 
Unraveling the Layers of Design Thinking.pptx
Unraveling the Layers of Design Thinking.pptxUnraveling the Layers of Design Thinking.pptx
Unraveling the Layers of Design Thinking.pptx
 
Making Innovation Possible in the Healthcare Domain
Making Innovation Possible in the Healthcare DomainMaking Innovation Possible in the Healthcare Domain
Making Innovation Possible in the Healthcare Domain
 
Future of Internet Web 3.0
Future of Internet Web 3.0Future of Internet Web 3.0
Future of Internet Web 3.0
 
The Future of IoT Technology in year 2022
The Future of IoT Technology in year 2022The Future of IoT Technology in year 2022
The Future of IoT Technology in year 2022
 
The World of Industrial IoT
The World of Industrial IoTThe World of Industrial IoT
The World of Industrial IoT
 
Get started on the IoT journey
Get started on the IoT journeyGet started on the IoT journey
Get started on the IoT journey
 
Exploring the emerging IoT technology
Exploring the emerging IoT technologyExploring the emerging IoT technology
Exploring the emerging IoT technology
 
Ux Independent of Digital Products
Ux Independent of Digital ProductsUx Independent of Digital Products
Ux Independent of Digital Products
 
Driving Digital Transformation with SAP Cloud Integration
Driving Digital Transformation with SAP Cloud IntegrationDriving Digital Transformation with SAP Cloud Integration
Driving Digital Transformation with SAP Cloud Integration
 
Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!
Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!
Public Cloud vs Private Cloud – Choosing the Right Cloud Computing Environment!
 
The Future of Cloud Computing in 2021
The Future of Cloud Computing in 2021The Future of Cloud Computing in 2021
The Future of Cloud Computing in 2021
 
Solving Business Problems with Machine Learning in SAP Analytics Cloud
Solving Business Problems with Machine Learning in SAP Analytics CloudSolving Business Problems with Machine Learning in SAP Analytics Cloud
Solving Business Problems with Machine Learning in SAP Analytics Cloud
 

Recently uploaded

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
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
 
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
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 

Recently uploaded (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
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
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
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
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 

5 Simple Tips to Young Developers for Writing a ‘Clean’ Code

  • 1. www.extentia.com | Confidential WRITING A ‘CLEAN’ CODE Simple Tips for Young Developers
  • 2. www.extentia.com | Confidential What is a Clean Code? • A code that can be easily read, understood, maintained, and extended • Indicates the maintainability and extensibility of the code for years (if not decades!) • Ideally, sustainable from the people who originally wrote it to the developers who joined in later
  • 3. www.extentia.com | Confidential The Need for Clean Codes Addressing issues with the application of SOLID principles or some of the other design patterns: • Difficult to apply in practical situations while under pressure • Subject to multiple interpretations and can be confusing • Understanding them requires a certain level of experience • Classroom teaching, alone, may not be sufficient
  • 4. www.extentia.com | Confidential 5 Simple Tips For Writing a Clean Code
  • 5. www.extentia.com | Confidential Think Before You Type! • Every line of code is a potential cause for a bug • Hence, you must think very deeply before: • Naming variables • Organizing code into blocks, functions, etc. • Think from the perspective of another developer • So, multiple developers can maintain the code for years
  • 6. www.extentia.com | Confidential Avoid ‘Ladder-to-Hell’ Patterns • ‘Ladder-to-Hell’ pattern • One of the most used programming patterns; resembles the code given on the right • Occurs when lots of nested if-else, for and while loops are used • Makes the code untestable and un-maintainable • Can be avoided by • Decomposing the blocks to functions till the leaf(ves) has just ONE ‘if-else’ block • Using Sonar or other static analysis tools to detect and eliminate them
  • 7. www.extentia.com | Confidential Write Computational Logic as ‘Pure’ Functions • Do NOT mix I/O operations with computational logic • I/O operations make computational logic difficult to test using automation • Testing such a function requires mocking the DB and building other scaffolding • Code on the right is an example of how it should be written • To make the processResultSet() function testable using automated unit tests
  • 8. www.extentia.com | Confidential Keep the Length of Functions to Less Than 35 • Programming is about decomposing problems into smaller problems and then composing them back into a whole • Smaller functions are easier to understand • Long functions require scrolling up and down continuously, causing mental and physical strain • A function should be visible on a single screen in the smallest device
  • 9. www.extentia.com | Confidential Keep the Conditionals at Less Than 7 • Restrict the cyclomatic complexity (if- statements, termination of loops, etc.) to less than 7, because • Human short-term memory holds up to 7 pieces of information at once • As the number increases, our ability to comprehend reduces • Lesser cyclomatic complexity leads to a lesser number of unit tests
  • 11. www.extentia.com | Confidential Thank You! Write to us at inquiries.extentia.com to learn more! More about Extentia’s offerings at https://www.extentia.com