SlideShare uma empresa Scribd logo
1 de 26
{Clean Code}
The fundamental of high quality software
presented by Arif Akbarul Huda (twitter @omayib)
Interesting Quotes
“Writing code is more like write a book. An other pepople will read and
use it. Keep it human readible instead of mechine readible.” @omayib
(6/2/2017)
“Buat aplikasi itu juga harus mikir gimana caranya bisa didebug
dengan gampang. Ndak kayak gini juga. Edan” @linklunx (25/1/2017)
Software quality & Productivity are realted. Better quality leads
to enhanced productivity” @_ericelliot (4/12/2016)
Problem state
Are you worried after publish your
application to the store?
did you found any side effect after
do refactoring?
Oh no! We have a spaghety code
Let’s make our code cleaner than
before.
1. Meaningful names
Use descriptive name
This is bad:
protected $d; // elapsed time in days
This is good:
protected $elapsedTimeInDays;
protected $daysSinceCreation;
protected $daysSinceModification;
protected $fileAgeInDays;
Use pronounceable name
This is bad:
public $genymdhms;
public $modymdhms;
This is good:
public $generationTimestamp;
public $modificationTimestamp;
Use namespaces instead of prefixing names
This is bad:
class Part {
private $m_dsc;
} 
This is good:
class Part {
private $description;
} 
Don't be cute
This is bad:
$program­>whack();
This is good:
$program­>kill();
Use one word per one concept.
This is Bad :
void LoadSingleData()
void FetchDataFiltered()
Void GetAllData()
This is Better :
void SetDataToView();
void SetObjectValue(int value)
Use meaningful names in their self context
This is bad :
string addressCity;
string addressHomeNumber;
string addressPostCode;
This is better :
class Address{
string city;
string homeNumber;
string postCode;
}
https://blog.goyello.com/2013/05/17/express-names-in-code-bad-vs-clean/
2. Better Function
The smaller the better
A function should only do one thing
public void purchase(List<Item> items){
    if(user.getAge>17 && database != null ){
        database.connect();
        boolean status = database.save(items);
        if(status==true){
            textLabel.setText("purchase succeed");
        }
    }
}
public void purchase(List<Item> items){
    if(user.isAllowed()){
        try {
            user.purcashe(items);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Less arguments are better
More than three arguments are evil. For example:
Circle makeCircle(Point center, double radius);
Is better than
Circle makeCircle(double x, double y, double radius);
3. Comment
Don’t comment bad code, rewrite it
If code is readable you don’t need
comments
This is bad:
// Check to see if the employee is eligible for full benefits
if ($employee­>flags && self::HOURLY_FLAG && 
$employee­>age > 65) 
This is good:
if ($employee­>isEligibleForFullBenefits())
Explain your intention in comments :
// if we sort the array here the logic 
// becomes simpler in calculatePayment() 
// method
Warn of consequences in comments :
// this script will take a very long time 
// to run 
Emphasis important points in comments :
// the trim function is very important, in 
// most cases the username has a trailing 
// space
Noise comments are bad :
/** The day of the month. */
private $dayOfMonth;
4. S.O.L.I.D. Priciple
S – Single-responsiblity principle
O – Open-closed principle
L – Liskov substitution principle
I – Interface segregation principle
D – Dependency Inversion Principle
TOBE CONTINUE >>
Recommended Books

Mais conteúdo relacionado

Semelhante a clean code for high quality software

Nirdesh_Developer_2.0_Years_6_months_Exp
Nirdesh_Developer_2.0_Years_6_months_ExpNirdesh_Developer_2.0_Years_6_months_Exp
Nirdesh_Developer_2.0_Years_6_months_Exp
Nirdesh Kulshreshtha
 

Semelhante a clean code for high quality software (20)

Sudipta mukherjee 2016_2017
Sudipta mukherjee 2016_2017Sudipta mukherjee 2016_2017
Sudipta mukherjee 2016_2017
 
Sudipta_Mukherjee_2016_2017
Sudipta_Mukherjee_2016_2017Sudipta_Mukherjee_2016_2017
Sudipta_Mukherjee_2016_2017
 
Dev Learn Handout - Session 604
Dev Learn Handout - Session 604Dev Learn Handout - Session 604
Dev Learn Handout - Session 604
 
Androids
AndroidsAndroids
Androids
 
Multi-Team Development w Ember, Angular, Knockout etc @ Interactive Intelligence
Multi-Team Development w Ember, Angular, Knockout etc @ Interactive IntelligenceMulti-Team Development w Ember, Angular, Knockout etc @ Interactive Intelligence
Multi-Team Development w Ember, Angular, Knockout etc @ Interactive Intelligence
 
Building a DevSecOps Pipeline Around Your Spring Boot Application
Building a DevSecOps Pipeline Around Your Spring Boot ApplicationBuilding a DevSecOps Pipeline Around Your Spring Boot Application
Building a DevSecOps Pipeline Around Your Spring Boot Application
 
Resources and relationships at front-end
Resources and relationships at front-endResources and relationships at front-end
Resources and relationships at front-end
 
React Native App Development in 2023-Tips to Practice.pdf
React Native App Development in 2023-Tips to Practice.pdfReact Native App Development in 2023-Tips to Practice.pdf
React Native App Development in 2023-Tips to Practice.pdf
 
Time to Good DX
Time to Good DXTime to Good DX
Time to Good DX
 
Resume
ResumeResume
Resume
 
Best Great Ideas on Java Research Papers
Best Great Ideas on Java Research PapersBest Great Ideas on Java Research Papers
Best Great Ideas on Java Research Papers
 
Putting Mobile First by Lindsay Herbert
Putting Mobile First by Lindsay HerbertPutting Mobile First by Lindsay Herbert
Putting Mobile First by Lindsay Herbert
 
Mobile Strategy 2013
Mobile Strategy 2013Mobile Strategy 2013
Mobile Strategy 2013
 
Cv vipul valvi_java_developer
Cv vipul valvi_java_developerCv vipul valvi_java_developer
Cv vipul valvi_java_developer
 
Resume
ResumeResume
Resume
 
spurthy_resume
spurthy_resumespurthy_resume
spurthy_resume
 
Nirdesh_Developer_2.0_Years_6_months_Exp
Nirdesh_Developer_2.0_Years_6_months_ExpNirdesh_Developer_2.0_Years_6_months_Exp
Nirdesh_Developer_2.0_Years_6_months_Exp
 
Top Object-Oriented Programming Languages To Follow In December 2022.pdf
Top Object-Oriented Programming Languages To Follow In December 2022.pdfTop Object-Oriented Programming Languages To Follow In December 2022.pdf
Top Object-Oriented Programming Languages To Follow In December 2022.pdf
 
Think horizontally ood, ddd and bdd
Think horizontally ood, ddd and bddThink horizontally ood, ddd and bdd
Think horizontally ood, ddd and bdd
 
Think horizontally @Codemotion
Think horizontally @CodemotionThink horizontally @Codemotion
Think horizontally @Codemotion
 

Mais de Arif Huda

Mais de Arif Huda (20)

Spotify Recommender System
Spotify Recommender SystemSpotify Recommender System
Spotify Recommender System
 
Startup Tanpa Mentor, Bisa?
Startup Tanpa Mentor, Bisa?Startup Tanpa Mentor, Bisa?
Startup Tanpa Mentor, Bisa?
 
Introducing Startup 101
Introducing Startup 101Introducing Startup 101
Introducing Startup 101
 
Solusi Mencegah Coding Ruwet
Solusi Mencegah Coding RuwetSolusi Mencegah Coding Ruwet
Solusi Mencegah Coding Ruwet
 
Bedah Teknologi Semacam Gojek
Bedah Teknologi Semacam GojekBedah Teknologi Semacam Gojek
Bedah Teknologi Semacam Gojek
 
Rahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 Tahun
Rahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 TahunRahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 Tahun
Rahasia Mendapatkan Investasi Milyaran Rupiah Sebelum Usia 30 Tahun
 
Membuat Media Edukasi Daring
Membuat Media Edukasi DaringMembuat Media Edukasi Daring
Membuat Media Edukasi Daring
 
Single responsibility pattern
Single responsibility patternSingle responsibility pattern
Single responsibility pattern
 
5 jalan rahasia mewujudkan ide startup
5 jalan rahasia mewujudkan ide startup5 jalan rahasia mewujudkan ide startup
5 jalan rahasia mewujudkan ide startup
 
programmersworld
programmersworldprogrammersworld
programmersworld
 
5 Langkah Jitu Melejitkan Ide Bisnis Startup
5 Langkah Jitu Melejitkan Ide Bisnis Startup5 Langkah Jitu Melejitkan Ide Bisnis Startup
5 Langkah Jitu Melejitkan Ide Bisnis Startup
 
getting started startup in millenial era
getting started startup in millenial eragetting started startup in millenial era
getting started startup in millenial era
 
Fingertip Detection
Fingertip DetectionFingertip Detection
Fingertip Detection
 
Protocol oriented programming
Protocol oriented programmingProtocol oriented programming
Protocol oriented programming
 
an implementation of repository pattern for mobile application
an implementation of repository pattern for mobile applicationan implementation of repository pattern for mobile application
an implementation of repository pattern for mobile application
 
Inovasi Teknologi Berkemajuan
Inovasi Teknologi BerkemajuanInovasi Teknologi Berkemajuan
Inovasi Teknologi Berkemajuan
 
Git workflow
Git workflowGit workflow
Git workflow
 
Media pembelajaran audio untuk tunanetra
Media pembelajaran audio untuk tunanetraMedia pembelajaran audio untuk tunanetra
Media pembelajaran audio untuk tunanetra
 
Tobe a superstar programmer
Tobe a superstar programmerTobe a superstar programmer
Tobe a superstar programmer
 
Seminar nasional internet of things 2016
Seminar nasional internet of things 2016Seminar nasional internet of things 2016
Seminar nasional internet of things 2016
 

Último

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Último (20)

VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 

clean code for high quality software