SlideShare a Scribd company logo
Clean code ch02
Clean Code
‫نویسنده‬:Robert C. Martin
‫سال‬:2008
‫مطالب‬ ‫سرفصل‬
1.Meaningful Names
2.Functions
3.Comments
4.Formatting
5.Error Handling
6.Boundires
7.Unit Tests
8.Class
‫ی‬‫نامگذار‬ ‫قواعد‬:
1.‫معلوم‬ ‫های‬ ‫نام‬‫از‬‫استفاده‬
4.‫بیان‬‫قابل‬
3.‫گردد‬ ‫تمایز‬‫باعث‬ ‫گه‬ ‫ای‬ ‫کلمه‬ ‫از‬‫استفاده‬
5.‫باشد‬ ‫جستجو‬ ‫قابل‬‫سریع‬
8.‫مفهوم‬ ‫یک‬‫ای‬‫ر‬‫ب‬ ‫کلمه‬ ‫یک‬
6.‫پیشوند‬
7.‫ذهنی‬ ‫کلمات‬
2.‫غلط‬ ‫اطالعات‬ ‫از‬‫اجتناب‬
Soultion Domain Names 9.
‫ل‬‫او‬ ‫قاعده‬:
1Small
1.‫باید‬ ‫تابع‬ ‫هر‬2‫الی‬3‫الی‬4‫باشد‬ ‫خط‬.
2.‫باشد‬ ‫شفاف‬.
3.‫کند‬ ‫بیان‬‫ا‬‫ر‬ ‫داستان‬ ‫یک‬ ‫تابع‬‫هر‬.
‫ل‬‫او‬ ‫قاعده‬:
1Small
‫ل‬‫او‬ ‫قاعده‬:
1Small
‫ل‬‫او‬ ‫قاعده‬:
1Small
‫دوم‬ ‫قاعده‬:
2Do One Thing
Function do one thing,
they should dot it well.
They should do it Only.
‫دوم‬ ‫قاعده‬:
2Do One Thing
‫دوم‬ ‫قاعده‬:
2Do One Thing
‫دوم‬ ‫قاعده‬:
2Do One Thing
‫دوم‬ ‫قاعده‬:
2Do One Thing
‫دوم‬ ‫قاعده‬:
2Do One Thing
‫دوم‬ ‫قاعده‬:
2Do One Thing
‫سوم‬ ‫قاعده‬:
3One Level of abstraction per function
One Level of Abstraction per function
getHtml();
//Hight level of abstraction
//Intermediate level of abstraction
String pagePathName = PathParse.Render(pagePath);
‫م‬‫ر‬‫چها‬‫قاعده‬:
4Switch Statement
‫م‬‫ر‬‫چها‬‫قاعده‬:
4Switch Statement
public class Bird
{
public double GetSpeed()
{
switch (type)
{
case EUROPEAN:
return GetBaseSpeed();
case AFRICAN:
return GetBaseSpeed() - GetLoadFactor() * numberOfCoconuts;
case NORWEGIAN_BLUE:
return isNailed ? 0 : GetBaseSpeed(voltage);
default:
throw new Exception("Should be unreachable");
}
}
}
‫م‬‫ر‬‫چها‬‫قاعده‬:
4Switch Statement
public abstract class Bird
{
public abstract double GetSpeed();
}
class European: Bird
{
public override double GetSpeed()
{
return GetBaseSpeed();
}
}
class African: Bird
{
public override double GetSpeed()
{
return GetBaseSpeed() - GetLoadFactor() *
numberOfCoconuts;
}
}
class NorwegianBlue: Bird
{
public override double GetSpeed()
{
return isNailed ? 0 : GetBaseSpeed(voltage);
}
}
‫م‬‫ر‬‫چها‬‫قاعده‬:
4Switch Statement
‫پنجم‬ ‫قاعده‬:
5Use Descriptive Name
‫ششم‬ ‫قاعده‬:
6Function Argument
More than three or four parameters for a method.
6Function Argument ‫ششم‬ ‫قاعده‬:
‫هفتم‬ ‫قاعده‬:
7Argument Objects
Compare:
Circle makeCircle(double x, double y, double radius);
vs
Circle makeCircle(Point center, double radius);
‫هشتم‬ ‫قاعده‬:
8Have No Side Effects
‫نهم‬ ‫قاعده‬:
9Don’t repeat yourself
‫دهم‬ ‫قاعده‬:
10Prefer Exceptions to Returning Error Codes
Command Query Separation
Functions should either do something or answer something, but not
both. Either your function should change the state of an object, or
it should return some information about that object. Doing both
often leads to confusion.
Returning error codes from command functions is a subtle violation of
command query separation.
‫توابع‬ ‫قاعده‬:
1.Small
2.Do One Thing
3.One Level Of Abstractions
4.Switch Case Statement
5.Use Descriptive Names
6.Function Arguments
8.Have No Side Effect
9.Don’t Repeat Yourself
10. Prefer Exceptions to Returning Error Codes
7. Argument Objects

More Related Content

PPT
Basic Javascript
PDF
Clean Code�Chapter 3. (1)
PPT
Covariance, contravariance 觀念分享
PDF
Javascript basic course
PPTX
2. Design patterns. part #2
PPTX
Jsp session 12
PPTX
JavaScript Proven Practises
ODP
Decompiling Java - SCAM2009 Presentation
Basic Javascript
Clean Code�Chapter 3. (1)
Covariance, contravariance 觀念分享
Javascript basic course
2. Design patterns. part #2
Jsp session 12
JavaScript Proven Practises
Decompiling Java - SCAM2009 Presentation

Similar to Clean code ch02 (20)

PPTX
Clean code ch03
PPTX
Adding a modern twist to legacy web applications
PDF
Wide Search Molecular Replacement and the NEBioGrid portal interface
DOCX
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
PPTX
PPTX
The software design principles
PDF
Os Django
PPT
Strategy and Template Pattern
PPTX
Java script best practices v4
PDF
Migrating Puppet 3 to 4 -- Code Changes
PPTX
Intro to Rails 4
PPTX
Modular javascript
PDF
Clean code and code smells
PPT
00_Introduction to Java.ppt
KEY
Aprendendo solid com exemplos
PPTX
Java SE 17 Study Guide for Certification - Chapter 01
PDF
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
PDF
Important JavaScript Concepts Every Developer Must Know
PDF
Denis Radin - "Applying NASA coding guidelines to JavaScript or airspace is c...
PPT
Douglas Crockford Presentation Goodparts
Clean code ch03
Adding a modern twist to legacy web applications
Wide Search Molecular Replacement and the NEBioGrid portal interface
GDE Lab 1 – Traffic Light Pg. 1 Lab 1 Traffic L.docx
The software design principles
Os Django
Strategy and Template Pattern
Java script best practices v4
Migrating Puppet 3 to 4 -- Code Changes
Intro to Rails 4
Modular javascript
Clean code and code smells
00_Introduction to Java.ppt
Aprendendo solid com exemplos
Java SE 17 Study Guide for Certification - Chapter 01
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Important JavaScript Concepts Every Developer Must Know
Denis Radin - "Applying NASA coding guidelines to JavaScript or airspace is c...
Douglas Crockford Presentation Goodparts
Ad

Recently uploaded (20)

PDF
Nekopoi APK 2025 free lastest update
PDF
Digital Strategies for Manufacturing Companies
PDF
AI in Product Development-omnex systems
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
System and Network Administraation Chapter 3
PPTX
Essential Infomation Tech presentation.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
history of c programming in notes for students .pptx
Nekopoi APK 2025 free lastest update
Digital Strategies for Manufacturing Companies
AI in Product Development-omnex systems
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
VVF-Customer-Presentation2025-Ver1.9.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Design an Analysis of Algorithms I-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Reimagine Home Health with the Power of Agentic AI​
System and Network Administraation Chapter 3
Essential Infomation Tech presentation.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Understanding Forklifts - TECH EHS Solution
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Odoo Companies in India – Driving Business Transformation.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Softaken Excel to vCard Converter Software.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
history of c programming in notes for students .pptx
Ad

Clean code ch02