SlideShare a Scribd company logo
1 of 38
Clean Code
Whisnu | Vox Teneo Indonesia
Reason?
• We Are Programmer
• We Want to be a Better Programmer
A = 1
B = A
Print BA = 1
C = A
B = C
Print B - Same Task
- Same Effort
- Same Test Result
- No BUG’s
Good Code Matter
because it doesn't end there!
• You Will Have To Go Back
• Someone Else Will Have To Go Back
• They Don’t Teach That in School
• Good Code Matter
• Definition
• Degrees of Bad
• The Netscape Fallacy
• Why Write Good Code
• But Doesn't Good Code Cost More Up Front?
Boy Scout Rule
Leave the campground cleaner than you found it.
CLEAN CODE =
WTF’s
Minutes
Meaningful Names
Functions
Comments
Formatting
Objects and Data Structures
Error Handling
Unit Tests
Meaningful Names
int d; // elapsed time in days
string htmlOutput; // form configuration html
DataGrid dataGrid1;
DataGrid dataGrid2;
Label label1;
Object myObj;
int elapsedTimeInDays;
string formConfiguration;
DataGrid dgCustomers;
DataGrid dgProducts;
Label lblFirstName;
Object objCustomer;
Functions
• Small and Should be smaller than that
• Do One Thing
• One Level of Abstraction
• getHtml();
• String pagePathName = PathParser.render(path);
• .append(“n”);
• Switch Statement (break it for SRP/OCP reason)
• Ideal number of arguments is ZERO
• Object Argument (hidden dependency, inject dependency, SRP)
• Have No Side Effect (setAndCheckIfExists())
Comment
• Don’t Comment Bad Code!
• Explain on Code
• Legal comment, TODO comment, JavaDoc, PHPDocumenter
• Clarification
• Warning of Consequences
• No Mumbling
• Redudant Comment
• Position Marker
• Closing Brace comment
• Attributes and ByLine
• Comment Out Code (your note code)
Formating
• The Purpose of Formatting?
• Vertical Matter, Horizontal Alignment
• Breaking Identation
• Team Rules
Object and Data Structures*
• The Law Of Demeter (Train Wrecks)
* lol + m/ = 
Error Handling
• Prefer Returning an Exceptions
• Don’t Return null
Unit Tests
The Three Laws of TDD:
• First Law You may not write production code until you have written a
failing unit test.
• Second Law You may not write more of a unit test than is sufficient to
fail, and not compiling is failing.
• Third Law You may not write more production code than is sufficient
to pass the currently failing test.
In Practice it’s all about RTM
READABILITY
TESTABILITY
MAINTAINABILITY
From STUPID to SOLID
STUPI D
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
S OL I D
Single Responsibility Principle
Open/Close Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Single Responsibility Principle
Open/Close Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Single Responsibility Principle
Open/Close Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Single Responsibility Principle
Open/Close Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Single Responsibility Principle
Open/Close Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Single Responsibility Principle
Open/Close Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
For Coding Standard ?
…and any Questions?

More Related Content

What's hot (6)

TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
C after correction
C after correctionC after correction
C after correction
 
Implementing DSLs in practice
Implementing DSLs in practiceImplementing DSLs in practice
Implementing DSLs in practice
 
Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
[Question Paper] Web Technology (Revised Course) [June / 2014]
[Question Paper] Web Technology (Revised Course) [June / 2014][Question Paper] Web Technology (Revised Course) [June / 2014]
[Question Paper] Web Technology (Revised Course) [June / 2014]
 

Viewers also liked

Viewers also liked (20)

Waarom ontwikkelt elk kind zich anders - prof. dr. Frank Verhulst
Waarom ontwikkelt elk kind zich anders - prof. dr. Frank VerhulstWaarom ontwikkelt elk kind zich anders - prof. dr. Frank Verhulst
Waarom ontwikkelt elk kind zich anders - prof. dr. Frank Verhulst
 
Cloud Camp Azure概要
Cloud Camp Azure概要Cloud Camp Azure概要
Cloud Camp Azure概要
 
Fun git hub
Fun git hubFun git hub
Fun git hub
 
Stephenson big data utrecht 2017
Stephenson   big data utrecht 2017Stephenson   big data utrecht 2017
Stephenson big data utrecht 2017
 
Node.JS error handling best practices
Node.JS error handling best practicesNode.JS error handling best practices
Node.JS error handling best practices
 
Silicon Valley Grade IT and Cloud Maturity Assessment for Startup Ecosystem i...
Silicon Valley Grade IT and Cloud Maturity Assessment for Startup Ecosystem i...Silicon Valley Grade IT and Cloud Maturity Assessment for Startup Ecosystem i...
Silicon Valley Grade IT and Cloud Maturity Assessment for Startup Ecosystem i...
 
Vasilis Bankov & Calin Iliescu AEGON
Vasilis Bankov & Calin Iliescu AEGONVasilis Bankov & Calin Iliescu AEGON
Vasilis Bankov & Calin Iliescu AEGON
 
Pre-Con Ed: Discover the New CA App Experience Analytics 16.3 - The Omnichann...
Pre-Con Ed: Discover the New CA App Experience Analytics 16.3 - The Omnichann...Pre-Con Ed: Discover the New CA App Experience Analytics 16.3 - The Omnichann...
Pre-Con Ed: Discover the New CA App Experience Analytics 16.3 - The Omnichann...
 
Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)
 
Oracle Cloud Café IOT 12 avril 2016
Oracle Cloud Café IOT 12 avril 2016Oracle Cloud Café IOT 12 avril 2016
Oracle Cloud Café IOT 12 avril 2016
 
Fontys eric van tol
Fontys eric van tolFontys eric van tol
Fontys eric van tol
 
Drive faster & better software delivery with performance monitoring & DevOps
Drive faster & better software delivery with performance monitoring & DevOpsDrive faster & better software delivery with performance monitoring & DevOps
Drive faster & better software delivery with performance monitoring & DevOps
 
ecdevday4
ecdevday4ecdevday4
ecdevday4
 
Oracle OpenWorld - A quick take on all 22 press releases of Day #1 - #3
Oracle OpenWorld - A quick take on all 22 press releases of Day #1 - #3Oracle OpenWorld - A quick take on all 22 press releases of Day #1 - #3
Oracle OpenWorld - A quick take on all 22 press releases of Day #1 - #3
 
Boston Devops Meetup June 22nd
Boston Devops Meetup June 22ndBoston Devops Meetup June 22nd
Boston Devops Meetup June 22nd
 
Andreas weigend
Andreas weigendAndreas weigend
Andreas weigend
 
Rb wilmer peres
Rb wilmer peresRb wilmer peres
Rb wilmer peres
 
App infrastructure &_integration_keynote_final
App infrastructure &_integration_keynote_finalApp infrastructure &_integration_keynote_final
App infrastructure &_integration_keynote_final
 
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
 
Cigniti joint webinar with Soasta - Agile DevOps: Test-driven IT Environment ...
Cigniti joint webinar with Soasta - Agile DevOps: Test-driven IT Environment ...Cigniti joint webinar with Soasta - Agile DevOps: Test-driven IT Environment ...
Cigniti joint webinar with Soasta - Agile DevOps: Test-driven IT Environment ...
 

Similar to Are You Ready For Clean Code?

Similar to Are You Ready For Clean Code? (20)

Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
 
Clean code
Clean codeClean code
Clean code
 
Clean code and code smells
Clean code and code smellsClean code and code smells
Clean code and code smells
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
TDD In Practice
TDD In PracticeTDD In Practice
TDD In Practice
 
CLEAN CODE
CLEAN CODECLEAN CODE
CLEAN CODE
 
An Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven DevelopmentAn Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven Development
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the Untestable
 
Test Driven Development - a gentle introduction
Test Driven Development - a gentle introductionTest Driven Development - a gentle introduction
Test Driven Development - a gentle introduction
 
Coding Standards
Coding StandardsCoding Standards
Coding Standards
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Clean Code
Clean CodeClean Code
Clean Code
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Clean code
Clean codeClean code
Clean code
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 

Recently uploaded

If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
David Celestin
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 

Recently uploaded (15)

If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 

Are You Ready For Clean Code?

Editor's Notes

  1. Revealing names Avoid Disinformation (ex: paymentStat) Meaningful Distinct (same name on one place, make other bad) Pronouncable Searchable Class Must noun, But Method must Verb Don’t be cute Pick one word per concept Don’t Joke Konsisten Mental Mapping = a, b == I,j,k
  2. Single Responsibilty Principle Open/Close Principle Niliadic, monadic, dyadic, triadic, polyadic (requires very special justification) DRY -> duplication may be the root of all evil in software Structured
  3. Clarification assertTrue(a.compareTo(b)==-1) ; // a < b Journal comment Noise comment Construct The day of month : private int dayOfMonth Scary comment private string name; // the name Private byte age; // the age To much information!!
  4. There is a well-known heuristic called the Law of Demeter2 that says a module should not know about the innards of the objects it manipulates. As we saw in the last section, objects hide their data and expose operations. This means that an object should not expose its internal structure through accessors because to do so is to expose, rather than to hide, its internal structure. Dog.getBody().getTail().wag(); Dog.expressHappiness();
  5. E_ERROR E_OK Return empty Collection.emptyList()
  6. Test Driven Development
  7. Readable code is understandable code Naming Class names Context specific Method names Say exactly what they do The don’ts Don’t confuse Don’t hide Don’t joke Don’t be informal Tell a story! ---------------------------------------------------------------- Making it testable, is making it clean Isolation Decoupling Separation of concerns TDD Design Clean is the side effect of testable ----------------------------------------------------------------- Easy to extend A change requires one change, not ten Easy to understand Unbrittle Test coverage Spreads optimism Importance level: Readable > maintainable