are you ready for clean code?
DESCRIPTION
What, when, how, and for whom is clean code? It's just ordinary weekly devTalk material at Vox Teneo Indonesia.TRANSCRIPT
![Page 1: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/1.jpg)
Clean CodeWhisnu | Vox Teneo Indonesia
![Page 2: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/2.jpg)
Reason?
• We Are Programmer• We Want to be a Better Programmer
![Page 3: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/3.jpg)
A = 1B = A
Print BA = 1C = AB = C
Print B - Same Task- Same Effort- Same Test Result- No BUG’s
Who’s code you choose?
![Page 4: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/4.jpg)
Who’s code you choose?
Does it matter how the code is written?
or does it only matter that it works?
![Page 5: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/5.jpg)
Good Code Matterbecause it doesn't end there!
![Page 6: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/6.jpg)
• 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?
![Page 7: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/7.jpg)
Boy Scout RuleLeave the campground cleaner than you found it.
![Page 8: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/8.jpg)
CLEAN CODE = WTF’sMinutes
![Page 9: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/9.jpg)
Meaningful NamesFunctions
CommentsFormatting
Objects and Data StructuresError Handling
Unit Tests
![Page 10: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/10.jpg)
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;
![Page 11: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/11.jpg)
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())
![Page 12: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/12.jpg)
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)
![Page 13: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/13.jpg)
Formating
• The Purpose of Formatting?• Vertical Matter, Horizontal Alignment• Breaking Identation• Team Rules
![Page 14: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/14.jpg)
Object and Data Structures*
• The Law Of Demeter (Train Wrecks)
* lol + \m/ =
![Page 15: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/15.jpg)
Error Handling
• Prefer Returning an Exceptions• Don’t Return null
![Page 16: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/16.jpg)
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.
![Page 17: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/17.jpg)
In Practice it’s all about RTM
![Page 18: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/18.jpg)
READABILITYTESTABILITY
MAINTAINABILITY
![Page 19: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/19.jpg)
![Page 20: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/20.jpg)
From STUPID to SOLID
![Page 21: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/21.jpg)
S T UPI D
![Page 22: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/22.jpg)
SingletonTight Coupling
UntestabilityPremature Optimization
Indescriptive NamingDuplication
![Page 23: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/23.jpg)
SingletonTight Coupling
UntestabilityPremature Optimization
Indescriptive NamingDuplication
![Page 24: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/24.jpg)
SingletonTight Coupling
UntestabilityPremature Optimization
Indescriptive NamingDuplication
![Page 25: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/25.jpg)
SingletonTight Coupling
UntestabilityPremature Optimization
Indescriptive NamingDuplication
![Page 26: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/26.jpg)
SingletonTight Coupling
UntestabilityPremature Optimization
Indescriptive NamingDuplication
![Page 27: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/27.jpg)
SingletonTight Coupling
UntestabilityPremature Optimization
Indescriptive NamingDuplication
![Page 28: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/28.jpg)
SingletonTight Coupling
UntestabilityPremature Optimization
Indescriptive NamingDuplication
![Page 29: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/29.jpg)
S OL I D
![Page 30: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/30.jpg)
Single Responsibility PrincipleOpen/Close Principle
Liskov Substitution PrincipleInterface Segregation Principle
Dependency Inversion Principle
![Page 31: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/31.jpg)
Single Responsibility PrincipleOpen/Close Principle
Liskov Substitution PrincipleInterface Segregation Principle
Dependency Inversion Principle
![Page 32: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/32.jpg)
![Page 33: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/33.jpg)
Single Responsibility PrincipleOpen/Close Principle
Liskov Substitution PrincipleInterface Segregation Principle
Dependency Inversion Principle
![Page 34: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/34.jpg)
Single Responsibility PrincipleOpen/Close Principle
Liskov Substitution PrincipleInterface Segregation Principle
Dependency Inversion Principle
![Page 35: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/35.jpg)
Single Responsibility PrincipleOpen/Close Principle
Liskov Substitution PrincipleInterface Segregation Principle
Dependency Inversion Principle
![Page 36: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/36.jpg)
Single Responsibility PrincipleOpen/Close Principle
Liskov Substitution PrincipleInterface Segregation Principle
Dependency Inversion Principle
![Page 37: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/37.jpg)
![Page 38: Are You Ready For Clean Code?](https://reader033.vdocuments.mx/reader033/viewer/2022052822/554f75c9b4c905bb178b546a/html5/thumbnails/38.jpg)
For Coding Standard ?
…and any Questions?