SlideShare une entreprise Scribd logo
1  sur  16
Introduction to Clean Code &
Names part I
By Niko Adrianus Yuwono
It is not the language that makes
programs appear simple. It is the
programmer that make the
language appear simple
 Dave Thomas says code can be described as a
clean code when :
1. The code is simple & direct.
2. Can be read, and enhanced by a developer
other thank it’s original author.
3. It has meaningful names.
4. It provides one way rather than many ways
for doing one thing.
5. It has minimal dependencies, which are
explicitly defined, and provides a clear and
minimal API.
 Code is the core of the application. Code
represents the details of the requirement.
Code is really the language in which we
ultimately express the requirements.
 If you’ve been in a team project you have
probably been significantly slowed down by
someone else’s messy code.
 Only knowing how to recognize clean code
from dirty code is not enough because it’s
doesn’t mean we know how to write clean
code.
 In this lecture we’ll do some exercises to help
us to know how to write clean code and make
it a habbit.
 Names are everywhere in software. We name
our variables, our functions, our arguments,
classes, and packages. We name our source
files and the directories that contain them.
 Because we do so much of it, we’d better do
it well. What follows are some simple rules for
creating good names.
 The name of a variable, function, or class,
should answer all the big questions. It should
tell you why it exists, what it does, and how it
is used. If a name requires a comment, then
the name does not reveal its intent.
int e; // total number of employee
 The name e reveals nothing. We should
choose a name that specifies what is being
measured and the unit of that measurement:
 Another example
int totalNumberOfEmployee;
int daysSinceLastLogin;
String employeeEmailAddress
 This is an example of dirty code
public ArrayList<int[]> getThem() {
ArrayList<int[]> ArrayList1 = new
ArrayList<int[]>();
for (int[] x : globalArrayList)
if (x[0] == 4)
ArrayList1.add(x);
return ArrayList1;
}
 Why is it a dirty code? Because we cannot
comprehend what’s the author want to
express in his code. The code is very implicit.
We must ask the author some question like :
1. What kinds of things are in globalArrayList?
2. What is the significance of the 0th subscript
of an item in globalArrayList?
3. What is the significance of the value 4?
4. How would I use the list being returned?
 We can rewrite the dirty code to this one:
public ArrayList<Member> getDietitianMember()
{
ArrayList<Member> dietitianMembersList =
new ArrayList<Member>();
for (Member member : allMemberList)
if (member[TYPE] == DIETITIAN)
dietitianMembersList.add(member);
return dietitianMembersList;
}
public ArrayList<Member>
getDietitianMember() {
ArrayList<Member> dietitianMembersList =
new ArrayList<Member>();
for (Member member : allMemberList)
if (member.isDietitian())
dietitianMembersList.add(x);
return dietitianMembersList;
}
 We should avoid words whose entrenched
meanings vary from our intended meaning.
 For example do not refer to a grouping of
accounts as an accountList unless it’s actually a
List.
 Beware of using names which vary in small ways.
How long does it take to spot the subtle
difference between a
XYZControllerForEfficientHandlingOfStrings in
one module and, somewhere a little more distant,
XYZControllerForEfficientStorageOfStrings?
 Usually when we can’t use the same name to
refer to two different things in the same
scope, we might be tempted to change one
name in an bad way like a1 and a2.
 It is not sufficient to add number series, even
though the compiler is satisfied. If names
must be different, then they should also
mean something different.
 This function is an example of a
noninformative function
 The use of variable a1 and a2 didn’t give us
clue what is the author intention.
public static void copyChars(char a1[], char
a2[]) {
for (int i = 0; i < a1.length; i++) {
a2[i] = a1[i];
}
}
 Some other example of indistinguishable
name :
1. money and moneyAmount
2. customer and customerInfo
3. accountData and account
4. theMessage and message

Contenu connexe

Tendances

Seo Expert course in Pakistan
Seo Expert course in PakistanSeo Expert course in Pakistan
Seo Expert course in Pakistanssuserb2c86f
 
Python functions part11
Python functions  part11Python functions  part11
Python functions part11Vishal Dutt
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to ErlangRaymond Tay
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1Srinimf-Slides
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsEng Teong Cheah
 
Encapsulation in C++
Encapsulation in C++Encapsulation in C++
Encapsulation in C++Hitesh Kumar
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismIt Academy
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Deepak Singh
 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in JavaDelowar Hossain
 
Some tips for taking the High School AP Java college board exam
Some tips for taking the High School  AP Java college board examSome tips for taking the High School  AP Java college board exam
Some tips for taking the High School AP Java college board examMichael Scaman
 

Tendances (20)

encapsulation
encapsulationencapsulation
encapsulation
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Seo Expert course in Pakistan
Seo Expert course in PakistanSeo Expert course in Pakistan
Seo Expert course in Pakistan
 
Python functions part11
Python functions  part11Python functions  part11
Python functions part11
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Python Tutorial Questions part-1
Python Tutorial Questions part-1Python Tutorial Questions part-1
Python Tutorial Questions part-1
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
 
Introduction to fuzzy logic
Introduction to fuzzy logicIntroduction to fuzzy logic
Introduction to fuzzy logic
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & Methods
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Oo ps exam answer2
Oo ps exam answer2Oo ps exam answer2
Oo ps exam answer2
 
Encapsulation in C++
Encapsulation in C++Encapsulation in C++
Encapsulation in C++
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Basic concept of Object Oriented Programming
Basic concept of Object Oriented Programming Basic concept of Object Oriented Programming
Basic concept of Object Oriented Programming
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding Polymorphism
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in Java
 
Some tips for taking the High School AP Java college board exam
Some tips for taking the High School  AP Java college board examSome tips for taking the High School  AP Java college board exam
Some tips for taking the High School AP Java college board exam
 

En vedette

CIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John Dasilva
CIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John DasilvaCIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John Dasilva
CIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John DasilvaCloudIDSummit
 
[Android] Google Play in app billing
[Android] Google Play in app billing[Android] Google Play in app billing
[Android] Google Play in app billingJun Shimizu
 
Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Daum DNA
 
Sales Methodologies - A quick guide to boosting success - realSociable
Sales Methodologies - A quick guide to boosting success - realSociableSales Methodologies - A quick guide to boosting success - realSociable
Sales Methodologies - A quick guide to boosting success - realSociableDalia Asterbadi
 
Slicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue PieSlicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue PieSam Gellar
 
Design Pattern with Burger
Design Pattern with BurgerDesign Pattern with Burger
Design Pattern with BurgerJun Shimizu
 
핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례Fingra.ph
 
realSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in MediarealSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in MediaDalia Asterbadi
 
NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...
NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...
NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...Dalia Asterbadi
 
Arputer overview 3413
Arputer overview   3413Arputer overview   3413
Arputer overview 3413arputer
 

En vedette (12)

CIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John Dasilva
CIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John DasilvaCIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John Dasilva
CIS 2015 SAML-IN / SAML-OUT - Scott Tomilson & John Dasilva
 
[Android] Google Play in app billing
[Android] Google Play in app billing[Android] Google Play in app billing
[Android] Google Play in app billing
 
Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기
 
Sales Methodologies - A quick guide to boosting success - realSociable
Sales Methodologies - A quick guide to boosting success - realSociableSales Methodologies - A quick guide to boosting success - realSociable
Sales Methodologies - A quick guide to boosting success - realSociable
 
Slicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue PieSlicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue Pie
 
Design Pattern with Burger
Design Pattern with BurgerDesign Pattern with Burger
Design Pattern with Burger
 
Verma sons
Verma sonsVerma sons
Verma sons
 
핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례
 
realSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in MediarealSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in Media
 
NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...
NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...
NextGen Customer Engagement - An Extension from Dave McClure's Pirate Startup...
 
Arputer overview 3413
Arputer overview   3413Arputer overview   3413
Arputer overview 3413
 
Piling lica
Piling licaPiling lica
Piling lica
 

Similaire à Clean code lecture part I

Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean CodeCleanestCode
 
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
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerIgor Crvenov
 
Bca winter 2013 2nd sem
Bca winter 2013 2nd semBca winter 2013 2nd sem
Bca winter 2013 2nd semsmumbahelp
 
Python breakdown-workbook
Python breakdown-workbookPython breakdown-workbook
Python breakdown-workbookHARUN PEHLIVAN
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxfestockton
 
Applying Generics
Applying GenericsApplying Generics
Applying GenericsBharat17485
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principlesEdorian
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddSrinivasa GV
 
Introduction to Refactoring
Introduction to RefactoringIntroduction to Refactoring
Introduction to RefactoringVorleak Chy
 

Similaire à Clean code lecture part I (20)

Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean Code
 
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
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 
Clean Code
Clean CodeClean Code
Clean Code
 
Bca winter 2013 2nd sem
Bca winter 2013 2nd semBca winter 2013 2nd sem
Bca winter 2013 2nd sem
 
Clean code
Clean codeClean code
Clean code
 
Python breakdown-workbook
Python breakdown-workbookPython breakdown-workbook
Python breakdown-workbook
 
BDD Primer
BDD PrimerBDD Primer
BDD Primer
 
Clean Code
Clean CodeClean Code
Clean Code
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
 
Clean code and code smells
Clean code and code smellsClean code and code smells
Clean code and code smells
 
Applying Generics
Applying GenericsApplying Generics
Applying Generics
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Clean code
Clean codeClean code
Clean code
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principles
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
 
Clean Code
Clean CodeClean Code
Clean Code
 
SAD10 - Refactoring
SAD10 - RefactoringSAD10 - Refactoring
SAD10 - Refactoring
 
Coding Checkpoints
Coding CheckpointsCoding Checkpoints
Coding Checkpoints
 
Introduction to Refactoring
Introduction to RefactoringIntroduction to Refactoring
Introduction to Refactoring
 

Dernier

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 

Clean code lecture part I

  • 1. Introduction to Clean Code & Names part I By Niko Adrianus Yuwono
  • 2. It is not the language that makes programs appear simple. It is the programmer that make the language appear simple
  • 3.  Dave Thomas says code can be described as a clean code when : 1. The code is simple & direct. 2. Can be read, and enhanced by a developer other thank it’s original author. 3. It has meaningful names. 4. It provides one way rather than many ways for doing one thing. 5. It has minimal dependencies, which are explicitly defined, and provides a clear and minimal API.
  • 4.  Code is the core of the application. Code represents the details of the requirement. Code is really the language in which we ultimately express the requirements.  If you’ve been in a team project you have probably been significantly slowed down by someone else’s messy code.
  • 5.  Only knowing how to recognize clean code from dirty code is not enough because it’s doesn’t mean we know how to write clean code.  In this lecture we’ll do some exercises to help us to know how to write clean code and make it a habbit.
  • 6.  Names are everywhere in software. We name our variables, our functions, our arguments, classes, and packages. We name our source files and the directories that contain them.  Because we do so much of it, we’d better do it well. What follows are some simple rules for creating good names.
  • 7.  The name of a variable, function, or class, should answer all the big questions. It should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent. int e; // total number of employee
  • 8.  The name e reveals nothing. We should choose a name that specifies what is being measured and the unit of that measurement:  Another example int totalNumberOfEmployee; int daysSinceLastLogin; String employeeEmailAddress
  • 9.  This is an example of dirty code public ArrayList<int[]> getThem() { ArrayList<int[]> ArrayList1 = new ArrayList<int[]>(); for (int[] x : globalArrayList) if (x[0] == 4) ArrayList1.add(x); return ArrayList1; }
  • 10.  Why is it a dirty code? Because we cannot comprehend what’s the author want to express in his code. The code is very implicit. We must ask the author some question like : 1. What kinds of things are in globalArrayList? 2. What is the significance of the 0th subscript of an item in globalArrayList? 3. What is the significance of the value 4? 4. How would I use the list being returned?
  • 11.  We can rewrite the dirty code to this one: public ArrayList<Member> getDietitianMember() { ArrayList<Member> dietitianMembersList = new ArrayList<Member>(); for (Member member : allMemberList) if (member[TYPE] == DIETITIAN) dietitianMembersList.add(member); return dietitianMembersList; }
  • 12. public ArrayList<Member> getDietitianMember() { ArrayList<Member> dietitianMembersList = new ArrayList<Member>(); for (Member member : allMemberList) if (member.isDietitian()) dietitianMembersList.add(x); return dietitianMembersList; }
  • 13.  We should avoid words whose entrenched meanings vary from our intended meaning.  For example do not refer to a grouping of accounts as an accountList unless it’s actually a List.  Beware of using names which vary in small ways. How long does it take to spot the subtle difference between a XYZControllerForEfficientHandlingOfStrings in one module and, somewhere a little more distant, XYZControllerForEfficientStorageOfStrings?
  • 14.  Usually when we can’t use the same name to refer to two different things in the same scope, we might be tempted to change one name in an bad way like a1 and a2.  It is not sufficient to add number series, even though the compiler is satisfied. If names must be different, then they should also mean something different.
  • 15.  This function is an example of a noninformative function  The use of variable a1 and a2 didn’t give us clue what is the author intention. public static void copyChars(char a1[], char a2[]) { for (int i = 0; i < a1.length; i++) { a2[i] = a1[i]; } }
  • 16.  Some other example of indistinguishable name : 1. money and moneyAmount 2. customer and customerInfo 3. accountData and account 4. theMessage and message