SlideShare une entreprise Scribd logo
1  sur  26
Clean Code


   “Master programmers think of
 systems as stories to be told rather
    than programs to be written”




                      By -: Uday Pratap Singh
Agenda

   What is clean code
   What makes us write bad code
   Talk about meaningful names
   How to make functions readable &
    understandable
Clean Code
A lot like painting a picture
What is clean code

   Is   it   Readable?
   Is   it   Maintainable?
   Is   it   Reusable?
   Is   it   Testable?
What is clean code
   Should be Readable like a well written
    book.
   Should be crisp. Contain only what is
    necessary.
   Provides one way rather than many ways
    of doing one thing.
   Does one thing well. Each class, function
    exposes single minded attitude.
What is clean code
   Easier for other people to enhance it.
   Smaller is better.
   Contains no duplication
   Close to expectations. No surprises
What is clean code


“You need to write that minimizes the
   time it would take someone else to
   understand it – even if that someone
   else is you – Dustin Boswell and
   Trevor Foucher”
Do you know?


       Time spent reading versus writing
               is well over 10:1




if you want your code to be easy to write, make it easy to read
Total cost of owning a Mess
What makes us write bad code?

   Were you trying to go fast?
   Tired of working on this program and
    wanted it to be over.
   Looked at the backlog
   To clean it up later.

    “We forget later equals never”
Why does good code rots?




       Requirements change
          Tight schedule
         Stupid Managers
                ...
Suppose if patient demands to stop hand
 washing because it’s taking too much time.
Doctor will refuse to do that because he knows
              the risk involved in it.


  Fault is Ours. We are Unprofessional.
Meaningful Names
Choosing meaningful name takes time
    but saves more than it takes
Rules
   Name should tell you why it exists, what it
    does, and how it is used
     e.g: int elapsedTimeInDays
   Make meaningful distinctions.
    e.g: customerInfo is indistinguishable
    from customer
   Use Pronounceable names.
    e.g: genymdhms
Rules Cont...
    No magic String or magic numbers.
    Use searchable names
    e.g; MAX_CLASSES_PER_STUDENT is
       easily searchable rather than 7.
    Pick one word per concept.
    eg: it’s confusing to have fetch, retrieve,
     and get as equivalent methods for
     different classes.
Rules Cont...
    You also don’t need to prefix member
     variables.
    e.g; personName variable in Person class
    Class names should have noun or noun
     phrase names like Customer, Account,
     AddressParser etc.
    Method name should start with the verb.
    e.g; postPayment, save, delete etc.
Rules Cont...
   Use problem domain names.
   Variable holding collection should be
    plural.
    e.g; persons, employees
   If a variable is expected to have a
    default value, then assign it at the time
    of declaration
Rules Cont...

   Don’t be cute.
       Choose clarity over entertainment value.
       Use kill rather than whack.
       Say what you mean. Mean what you say.
Functions
Should be easy to read and understand
    which communicates its intent
Rules
   Small should be smaller.
       Avoid more the 10 lines.
    Do not write more than 120 character in
     one line ( Line should be visible at one
     glance)
   Should be properly indented.
       It should not be more than 2.
       Blocks in if, else or loops should be only 1
        line. Probably that 1 line should be a method
        call.
Rules Cont..
   Do one thing.
       Should do it well.
       Should do it only.
   Avoid multiple return statements.
   Long descriptive name is better than
    long comment.
   Well defined parameters (with
    descriptive names) are better than a
    map as parameter.
Rules Cont...
   Step Down Rule – Code read from top to
    bottom.
   Function Arguments
       More than three (polyadic) requires very
        special justification—and then shouldn’t be
        used anyway.
   Passing flag argument is a terrible
    practice. It loudly proclaims that
    the function does more than one
     thing.
Rules Cont...
   Has no side effects.
       checkPassword method should only check
        whether password is correct or not, it should
        not initialize the user session. If we want to
        initialize the session then method name should
        be checkPasswordAndInitializeSession.
       Function should either change the state of
        object or it should return some information
        about the object. Doing both often leads to
        confusion.
Rules Cont...
   Prefer exception to returning error codes.
   Extract body of try catch blocks into
    method to increase the readability and
    structure of the code.
   DRY (Do not Repeat Yourself).
“Leave the campground cleaner
        than you found it”
Thanks...

Contenu connexe

Tendances

Clean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesClean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesRuth Sperer
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentSamnang Chhun
 
Clean code and Coding Standards
Clean code and Coding StandardsClean code and Coding Standards
Clean code and Coding StandardsMahesh Salaria
 
Advanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesAdvanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesMilan Vukoje
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software DevelopmentFolio3 Software
 
Real Life Unit Testing
Real Life Unit TestingReal Life Unit Testing
Real Life Unit TestingDror Helper
 
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)El Mahdi Benzekri
 
An Overview of automated testing (1)
An Overview of automated testing (1)An Overview of automated testing (1)
An Overview of automated testing (1)Rodrigo Lopes
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summaryJan de Vries
 
Behavior Driven Development
Behavior Driven Development Behavior Driven Development
Behavior Driven Development Dhawal Joshi
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design PrinciplesSerhiy Oplakanets
 
Being Good Developer
Being Good DeveloperBeing Good Developer
Being Good DeveloperSally Ahmed
 
Clean code - Getting your R&D on board
Clean code - Getting your R&D on boardClean code - Getting your R&D on board
Clean code - Getting your R&D on boardRuth Sperer
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelinesAnkur Goyal
 
Common design patterns in php
Common design patterns in phpCommon design patterns in php
Common design patterns in phpDavid Stockton
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guidelineDhananjaysinh Jhala
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelinesbrijraj_singh
 

Tendances (20)

Clean Code and Common Engineering Practices
Clean Code and Common Engineering PracticesClean Code and Common Engineering Practices
Clean Code and Common Engineering Practices
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Clean code and Coding Standards
Clean code and Coding StandardsClean code and Coding Standards
Clean code and Coding Standards
 
Advanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakesAdvanced unit testing – real life examples and mistakes
Advanced unit testing – real life examples and mistakes
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
 
Real Life Unit Testing
Real Life Unit TestingReal Life Unit Testing
Real Life Unit Testing
 
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
Caring About Code Quality (Clean Code, GRASP, Effective Java, Design Pattern)
 
An Overview of automated testing (1)
An Overview of automated testing (1)An Overview of automated testing (1)
An Overview of automated testing (1)
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summary
 
Behavior Driven Development
Behavior Driven Development Behavior Driven Development
Behavior Driven Development
 
"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles
 
Being Good Developer
Being Good DeveloperBeing Good Developer
Being Good Developer
 
Clean code - Getting your R&D on board
Clean code - Getting your R&D on boardClean code - Getting your R&D on board
Clean code - Getting your R&D on board
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
Common design patterns in php
Common design patterns in phpCommon design patterns in php
Common design patterns in php
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
 
Coding standard
Coding standardCoding standard
Coding standard
 
Code Review
Code ReviewCode Review
Code Review
 
Make a better with clean code
Make a better with clean codeMake a better with clean code
Make a better with clean code
 
Coding standards and guidelines
Coding standards and guidelinesCoding standards and guidelines
Coding standards and guidelines
 

En vedette

Limpiando espero la arquitectura que yo quiero
Limpiando espero la arquitectura que yo quieroLimpiando espero la arquitectura que yo quiero
Limpiando espero la arquitectura que yo quieroJose Manuel Pereira Garcia
 
Angularjs101-les_SPA:support de la video
Angularjs101-les_SPA:support de la videoAngularjs101-les_SPA:support de la video
Angularjs101-les_SPA:support de la videoeric German
 
Cleancode / Tocea / Introduction
Cleancode / Tocea / IntroductionCleancode / Tocea / Introduction
Cleancode / Tocea / IntroductionSylvain Leroy
 
Design applicatif avec symfony2
Design applicatif avec symfony2Design applicatif avec symfony2
Design applicatif avec symfony2RomainKuzniak
 
Visteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisasVisteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisasJosé María Pérez Ramos
 
Méthodologie de gestion des tâches dans les projets web
Méthodologie de gestion des tâches dans les projets webMéthodologie de gestion des tâches dans les projets web
Méthodologie de gestion des tâches dans les projets webRomainKuzniak
 
Solution de collecte intelligente des déchets (Ecube Labs)
Solution de collecte intelligente des déchets (Ecube Labs)Solution de collecte intelligente des déchets (Ecube Labs)
Solution de collecte intelligente des déchets (Ecube Labs)Ecube Labs
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
 
Composer in monolithic repositories
Composer in monolithic repositoriesComposer in monolithic repositories
Composer in monolithic repositoriesSten Hiedel
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome TownRoss Tuck
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Androidintive
 
Clean architecture with ddd layering in php
Clean architecture with ddd layering in phpClean architecture with ddd layering in php
Clean architecture with ddd layering in phpLeonardo Proietti
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravelwajrcs
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksPhill Sparks
 
Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2RomainKuzniak
 
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2Sofien Benrhouma
 

En vedette (20)

Limpiando espero la arquitectura que yo quiero
Limpiando espero la arquitectura que yo quieroLimpiando espero la arquitectura que yo quiero
Limpiando espero la arquitectura que yo quiero
 
Angularjs101-les_SPA:support de la video
Angularjs101-les_SPA:support de la videoAngularjs101-les_SPA:support de la video
Angularjs101-les_SPA:support de la video
 
Cleancode / Tocea / Introduction
Cleancode / Tocea / IntroductionCleancode / Tocea / Introduction
Cleancode / Tocea / Introduction
 
Clean architectures
Clean architecturesClean architectures
Clean architectures
 
DDD in PHP
DDD in PHPDDD in PHP
DDD in PHP
 
Design applicatif avec symfony2
Design applicatif avec symfony2Design applicatif avec symfony2
Design applicatif avec symfony2
 
Visteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisasVisteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisas
 
Méthodologie de gestion des tâches dans les projets web
Méthodologie de gestion des tâches dans les projets webMéthodologie de gestion des tâches dans les projets web
Méthodologie de gestion des tâches dans les projets web
 
Laravel 5 and SOLID
Laravel 5 and SOLIDLaravel 5 and SOLID
Laravel 5 and SOLID
 
Solution de collecte intelligente des déchets (Ecube Labs)
Solution de collecte intelligente des déchets (Ecube Labs)Solution de collecte intelligente des déchets (Ecube Labs)
Solution de collecte intelligente des déchets (Ecube Labs)
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Composer in monolithic repositories
Composer in monolithic repositoriesComposer in monolithic repositories
Composer in monolithic repositories
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Android
 
Clean architecture with ddd layering in php
Clean architecture with ddd layering in phpClean architecture with ddd layering in php
Clean architecture with ddd layering in php
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravel
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill Sparks
 
Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2Le pattern View Model avec Symfony2
Le pattern View Model avec Symfony2
 
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
Rapport Projet De Fin D'étude Développent d'une application web avec Symfony2
 

Similaire à Clean Code Fundamentals

Clean code - DSC DYPCOE
Clean code - DSC DYPCOEClean code - DSC DYPCOE
Clean code - DSC DYPCOEPatil Shreyas
 
Raya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityRaya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityAbdel Hady Muhammad
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
Clean Code - Writing code for human
Clean Code - Writing code for humanClean Code - Writing code for human
Clean Code - Writing code for humanNETKO Solution
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...DevDay.org
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringEyob Lube
 
Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job EasierTonya Mork
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential SkillsJohn Choi
 
Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!Diego Pacheco
 
Beyond the Style Guides
Beyond the Style GuidesBeyond the Style Guides
Beyond the Style GuidesMosky Liu
 
Code Smells - Refactoring
Code Smells - RefactoringCode Smells - Refactoring
Code Smells - RefactoringShobi P P
 
Clean code lecture part I
Clean code lecture part IClean code lecture part I
Clean code lecture part IJun Shimizu
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 

Similaire à Clean Code Fundamentals (20)

Clean code - DSC DYPCOE
Clean code - DSC DYPCOEClean code - DSC DYPCOE
Clean code - DSC DYPCOE
 
Clean Code
Clean CodeClean Code
Clean Code
 
Raya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readabilityRaya code quality guidelines - enhancing readability
Raya code quality guidelines - enhancing readability
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Clean Code - Writing code for human
Clean Code - Writing code for humanClean Code - Writing code for human
Clean Code - Writing code for human
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 
Naming Things
Naming ThingsNaming Things
Naming Things
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 
Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job Easier
 
Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
 
Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!
 
Beyond the Style Guides
Beyond the Style GuidesBeyond the Style Guides
Beyond the Style Guides
 
Clean code and code smells
Clean code and code smellsClean code and code smells
Clean code and code smells
 
Code Smells - Refactoring
Code Smells - RefactoringCode Smells - Refactoring
Code Smells - Refactoring
 
Clean code
Clean codeClean code
Clean code
 
Clean code lecture part I
Clean code lecture part IClean code lecture part I
Clean code lecture part I
 
Clean code
Clean codeClean code
Clean code
 
Clean_Code
Clean_CodeClean_Code
Clean_Code
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 

Dernier

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Dernier (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Clean Code Fundamentals

  • 1. Clean Code “Master programmers think of systems as stories to be told rather than programs to be written” By -: Uday Pratap Singh
  • 2. Agenda  What is clean code  What makes us write bad code  Talk about meaningful names  How to make functions readable & understandable
  • 3. Clean Code A lot like painting a picture
  • 4. What is clean code  Is it Readable?  Is it Maintainable?  Is it Reusable?  Is it Testable?
  • 5. What is clean code  Should be Readable like a well written book.  Should be crisp. Contain only what is necessary.  Provides one way rather than many ways of doing one thing.  Does one thing well. Each class, function exposes single minded attitude.
  • 6. What is clean code  Easier for other people to enhance it.  Smaller is better.  Contains no duplication  Close to expectations. No surprises
  • 7. What is clean code “You need to write that minimizes the time it would take someone else to understand it – even if that someone else is you – Dustin Boswell and Trevor Foucher”
  • 8. Do you know? Time spent reading versus writing is well over 10:1 if you want your code to be easy to write, make it easy to read
  • 9. Total cost of owning a Mess
  • 10. What makes us write bad code?  Were you trying to go fast?  Tired of working on this program and wanted it to be over.  Looked at the backlog  To clean it up later. “We forget later equals never”
  • 11. Why does good code rots? Requirements change Tight schedule Stupid Managers ...
  • 12. Suppose if patient demands to stop hand washing because it’s taking too much time. Doctor will refuse to do that because he knows the risk involved in it. Fault is Ours. We are Unprofessional.
  • 13. Meaningful Names Choosing meaningful name takes time but saves more than it takes
  • 14. Rules  Name should tell you why it exists, what it does, and how it is used e.g: int elapsedTimeInDays  Make meaningful distinctions. e.g: customerInfo is indistinguishable from customer  Use Pronounceable names. e.g: genymdhms
  • 15. Rules Cont...  No magic String or magic numbers.  Use searchable names e.g; MAX_CLASSES_PER_STUDENT is easily searchable rather than 7.  Pick one word per concept. eg: it’s confusing to have fetch, retrieve, and get as equivalent methods for different classes.
  • 16. Rules Cont...  You also don’t need to prefix member variables. e.g; personName variable in Person class  Class names should have noun or noun phrase names like Customer, Account, AddressParser etc.  Method name should start with the verb. e.g; postPayment, save, delete etc.
  • 17. Rules Cont...  Use problem domain names.  Variable holding collection should be plural. e.g; persons, employees  If a variable is expected to have a default value, then assign it at the time of declaration
  • 18. Rules Cont...  Don’t be cute.  Choose clarity over entertainment value.  Use kill rather than whack.  Say what you mean. Mean what you say.
  • 19. Functions Should be easy to read and understand which communicates its intent
  • 20. Rules  Small should be smaller.  Avoid more the 10 lines. Do not write more than 120 character in one line ( Line should be visible at one glance)  Should be properly indented.  It should not be more than 2.  Blocks in if, else or loops should be only 1 line. Probably that 1 line should be a method call.
  • 21. Rules Cont..  Do one thing.  Should do it well.  Should do it only.  Avoid multiple return statements.  Long descriptive name is better than long comment.  Well defined parameters (with descriptive names) are better than a map as parameter.
  • 22. Rules Cont...  Step Down Rule – Code read from top to bottom.  Function Arguments  More than three (polyadic) requires very special justification—and then shouldn’t be used anyway.  Passing flag argument is a terrible practice. It loudly proclaims that the function does more than one thing.
  • 23. Rules Cont...  Has no side effects.  checkPassword method should only check whether password is correct or not, it should not initialize the user session. If we want to initialize the session then method name should be checkPasswordAndInitializeSession.  Function should either change the state of object or it should return some information about the object. Doing both often leads to confusion.
  • 24. Rules Cont...  Prefer exception to returning error codes.  Extract body of try catch blocks into method to increase the readability and structure of the code.  DRY (Do not Repeat Yourself).
  • 25. “Leave the campground cleaner than you found it”