SlideShare una empresa de Scribd logo
1 de 18
Clean Code
By. Mohamed Essam
Code is clean if it can be understood easily –
by everyone on the team. Clean code can be
read and enhanced by a developer other
than its original author. With
understandability comes readability,
changeability, extensibility and
maintainability.
Code is clean if it can be understood easily –
by everyone on the team. Clean code can be
read and enhanced by a developer other
than its original author. With
understandability comes readability,
changeability, extensibility and
maintainability.
General rules
1.Follow standard conventions.
2.Keep it simple stupid. Simpler is always better. Reduce
complexity as much as possible.
3.Boy scout rule. Leave the campground cleaner than
you found it.
4.Always find root cause. Always look for the root cause
of a problem.
Names rules(meaningful name)
1.Choose descriptive and unambiguous names.
2.Make meaningful distinction.
3.Use pronounceable names.
4.Use searchable names.
5.Replace magic numbers with named constants.
6.Avoid encodings. Don't append prefixes or type
information.
Functions rules
1.Small.
2.Do one thing.
3.Use descriptive names.
4.Prefer fewer arguments.
5.Have no side effects.
6.Don't use flag arguments. Split method into several
independent methods that can be called from the client
without the flag.
Comments rules
1.Always try to explain yourself in code.
2.Don't be redundant.
3.Don't add obvious noise.
4.Don't use closing brace comments.
5.Don't comment out code. Just remove.
6.Use as explanation of intent.
7.Use as clarification of code.
8.Use as warning of consequences.
This called Dead code
Don't comment out code. Just remove.
Source code structure
1.Separate concepts vertically.
2.Related code should appear vertically dense.
3.Declare variables close to their usage.
4.Dependent functions should be close.
5.Similar functions should be close.
6.Place functions in the downward direction.
7.Keep lines short.
8.Don't use horizontal alignment.
9.Use white space to associate related things and
disassociate weakly related.
10.Don't break indentation.
Objects and data structures
1.Hide internal structure.
2.Prefer data structures.
3.Avoid hybrids structures (half object and half data).
4.Should be small.
5.Do one thing.
6.Small number of instance variables.
7.Base class should know nothing about their
derivatives.
8.Better to have many functions than to pass some code
into a function to select a behavior.
9.Prefer non-static methods to static methods.
Understandability tips
1.Be consistent. If you do something a certain way, do all
similar things in the same way.
2.Use explanatory variables.
3.Encapsulate boundary conditions. Boundary conditions are
hard to keep track of. Put the processing for them in one place.
4.Prefer dedicated value objects to primitive type.
5.Avoid logical dependency. Don't write methods which works
correctly depending on something else in the same class.
6.Avoid negative conditionals.
Design rules
1.Keep configurable data at high levels.
2.Prefer polymorphism to if/else or switch/case.
3.Separate multi-threading code.
4.Prevent over-configurability.
5.Use dependency injection.
6.Follow Law of Demeter. A class should know only
its direct dependencies.
Code smells
1.Rigidity. The software is difficult to change. A small
change causes a cascade of subsequent changes.
2.Fragility. The software breaks in many places due to a
single change.
3.Immobility. You cannot reuse parts of the code in
other projects because of involved risks and high effort.
4.Needless Complexity.
5.Needless Repetition.
6.Opacity. The code is hard to understand.
Use the DRY Concept
Don’t repeat yourself
Any Questions?
Mohamed Essam
!
CREDITS: This presentation template was created by Slidesgo,
including icons by Flaticon, and infographics & images by Freepik
THANKS!
Contacts
Mhmd96.essam@gmail.com
Please keep this slide for attribution

Más contenido relacionado

Similar a Clean_Code

Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
Ehtisham Ali
 
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
 

Similar a Clean_Code (20)

Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
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
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 
Chapter17 of clean code
Chapter17 of clean codeChapter17 of clean code
Chapter17 of 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#
 
[Php vigo][talk] unit testing sucks ( and it's your fault )
[Php vigo][talk] unit testing sucks ( and it's your fault )[Php vigo][talk] unit testing sucks ( and it's your fault )
[Php vigo][talk] unit testing sucks ( and it's your fault )
 
Clean code
Clean code Clean code
Clean code
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
C#
C#C#
C#
 
Bad Smells in Code
Bad Smells in CodeBad Smells in Code
Bad Smells in Code
 
Bade Smells in Code
Bade Smells in CodeBade Smells in Code
Bade Smells in Code
 
20140916 mcn pro_slidesppt
20140916 mcn pro_slidesppt20140916 mcn pro_slidesppt
20140916 mcn pro_slidesppt
 
Code Smells - Refactoring
Code Smells - RefactoringCode Smells - Refactoring
Code Smells - Refactoring
 
Clean code ch03
Clean code ch03Clean code ch03
Clean code ch03
 
Object Oriented Best Practices - Summary
Object Oriented Best Practices - SummaryObject Oriented Best Practices - Summary
Object Oriented Best Practices - Summary
 
Ruby Object Design
Ruby Object DesignRuby Object Design
Ruby Object Design
 
Ruby Object Design
Ruby Object DesignRuby Object Design
Ruby Object Design
 

Más de Mohamed Essam

2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx
Mohamed Essam
 

Más de Mohamed Essam (20)

Data Science Crash course
Data Science Crash courseData Science Crash course
Data Science Crash course
 
2.Feature Extraction
2.Feature Extraction2.Feature Extraction
2.Feature Extraction
 
Data Science
Data ScienceData Science
Data Science
 
Introduction to Robotics.pptx
Introduction to Robotics.pptxIntroduction to Robotics.pptx
Introduction to Robotics.pptx
 
Introduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxIntroduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptx
 
Getting_Started_with_DL_in_Keras.pptx
Getting_Started_with_DL_in_Keras.pptxGetting_Started_with_DL_in_Keras.pptx
Getting_Started_with_DL_in_Keras.pptx
 
Linear_algebra.pptx
Linear_algebra.pptxLinear_algebra.pptx
Linear_algebra.pptx
 
Let_s_Dive_to_Deep_Learning.pptx
Let_s_Dive_to_Deep_Learning.pptxLet_s_Dive_to_Deep_Learning.pptx
Let_s_Dive_to_Deep_Learning.pptx
 
OOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptxOOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptx
 
1.Basic_Syntax
1.Basic_Syntax1.Basic_Syntax
1.Basic_Syntax
 
KNN.pptx
KNN.pptxKNN.pptx
KNN.pptx
 
Regularization_BY_MOHAMED_ESSAM.pptx
Regularization_BY_MOHAMED_ESSAM.pptxRegularization_BY_MOHAMED_ESSAM.pptx
Regularization_BY_MOHAMED_ESSAM.pptx
 
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
 
Linear_Regression
Linear_RegressionLinear_Regression
Linear_Regression
 
2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx
 
Naieve_Bayee.pptx
Naieve_Bayee.pptxNaieve_Bayee.pptx
Naieve_Bayee.pptx
 
Activation_function.pptx
Activation_function.pptxActivation_function.pptx
Activation_function.pptx
 
Deep_Learning_Frameworks
Deep_Learning_FrameworksDeep_Learning_Frameworks
Deep_Learning_Frameworks
 
Neural_Network
Neural_NetworkNeural_Network
Neural_Network
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Clean_Code

  • 2. Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
  • 3. Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
  • 4. General rules 1.Follow standard conventions. 2.Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible. 3.Boy scout rule. Leave the campground cleaner than you found it. 4.Always find root cause. Always look for the root cause of a problem.
  • 5. Names rules(meaningful name) 1.Choose descriptive and unambiguous names. 2.Make meaningful distinction. 3.Use pronounceable names. 4.Use searchable names. 5.Replace magic numbers with named constants. 6.Avoid encodings. Don't append prefixes or type information.
  • 6.
  • 7. Functions rules 1.Small. 2.Do one thing. 3.Use descriptive names. 4.Prefer fewer arguments. 5.Have no side effects. 6.Don't use flag arguments. Split method into several independent methods that can be called from the client without the flag.
  • 8.
  • 9. Comments rules 1.Always try to explain yourself in code. 2.Don't be redundant. 3.Don't add obvious noise. 4.Don't use closing brace comments. 5.Don't comment out code. Just remove. 6.Use as explanation of intent. 7.Use as clarification of code. 8.Use as warning of consequences.
  • 10. This called Dead code Don't comment out code. Just remove.
  • 11. Source code structure 1.Separate concepts vertically. 2.Related code should appear vertically dense. 3.Declare variables close to their usage. 4.Dependent functions should be close. 5.Similar functions should be close. 6.Place functions in the downward direction. 7.Keep lines short. 8.Don't use horizontal alignment. 9.Use white space to associate related things and disassociate weakly related. 10.Don't break indentation.
  • 12. Objects and data structures 1.Hide internal structure. 2.Prefer data structures. 3.Avoid hybrids structures (half object and half data). 4.Should be small. 5.Do one thing. 6.Small number of instance variables. 7.Base class should know nothing about their derivatives. 8.Better to have many functions than to pass some code into a function to select a behavior. 9.Prefer non-static methods to static methods.
  • 13. Understandability tips 1.Be consistent. If you do something a certain way, do all similar things in the same way. 2.Use explanatory variables. 3.Encapsulate boundary conditions. Boundary conditions are hard to keep track of. Put the processing for them in one place. 4.Prefer dedicated value objects to primitive type. 5.Avoid logical dependency. Don't write methods which works correctly depending on something else in the same class. 6.Avoid negative conditionals.
  • 14. Design rules 1.Keep configurable data at high levels. 2.Prefer polymorphism to if/else or switch/case. 3.Separate multi-threading code. 4.Prevent over-configurability. 5.Use dependency injection. 6.Follow Law of Demeter. A class should know only its direct dependencies.
  • 15. Code smells 1.Rigidity. The software is difficult to change. A small change causes a cascade of subsequent changes. 2.Fragility. The software breaks in many places due to a single change. 3.Immobility. You cannot reuse parts of the code in other projects because of involved risks and high effort. 4.Needless Complexity. 5.Needless Repetition. 6.Opacity. The code is hard to understand.
  • 16. Use the DRY Concept Don’t repeat yourself
  • 18. CREDITS: This presentation template was created by Slidesgo, including icons by Flaticon, and infographics & images by Freepik THANKS! Contacts Mhmd96.essam@gmail.com Please keep this slide for attribution