Are You Ready For Clean Code?

38
Clean Code Whisnu | Vox Teneo Indonesia

description

What, when, how, and for whom is clean code? It's just ordinary weekly devTalk material at Vox Teneo Indonesia.

Transcript of Are You Ready For Clean Code?

Page 1: Are You Ready For Clean Code?

Clean CodeWhisnu | Vox Teneo Indonesia

Page 2: Are You Ready For Clean Code?

Reason?

• We Are Programmer• We Want to be a Better Programmer

Page 3: Are You Ready For Clean Code?

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?

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?

Good Code Matterbecause it doesn't end there!

Page 6: Are You Ready For Clean Code?

• 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?

Boy Scout RuleLeave the campground cleaner than you found it.

Page 8: Are You Ready For Clean Code?

CLEAN CODE = WTF’sMinutes

Page 9: Are You Ready For Clean Code?

Meaningful NamesFunctions

CommentsFormatting

Objects and Data StructuresError Handling

Unit Tests

Page 10: Are You Ready For Clean Code?

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?

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?

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?

Formating

• The Purpose of Formatting?• Vertical Matter, Horizontal Alignment• Breaking Identation• Team Rules

Page 14: Are You Ready For Clean Code?

Object and Data Structures*

• The Law Of Demeter (Train Wrecks)

* lol + \m/ =

Page 15: Are You Ready For Clean Code?

Error Handling

• Prefer Returning an Exceptions• Don’t Return null

Page 16: Are You Ready For Clean Code?

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?

In Practice it’s all about RTM

Page 18: Are You Ready For Clean Code?

READABILITYTESTABILITY

MAINTAINABILITY

Page 19: Are You Ready For Clean Code?
Page 20: Are You Ready For Clean Code?

From STUPID to SOLID

Page 21: Are You Ready For Clean Code?

S T UPI D

Page 22: Are You Ready For Clean Code?

SingletonTight Coupling

UntestabilityPremature Optimization

Indescriptive NamingDuplication

Page 23: Are You Ready For Clean Code?

SingletonTight Coupling

UntestabilityPremature Optimization

Indescriptive NamingDuplication

Page 24: Are You Ready For Clean Code?

SingletonTight Coupling

UntestabilityPremature Optimization

Indescriptive NamingDuplication

Page 25: Are You Ready For Clean Code?

SingletonTight Coupling

UntestabilityPremature Optimization

Indescriptive NamingDuplication

Page 26: Are You Ready For Clean Code?

SingletonTight Coupling

UntestabilityPremature Optimization

Indescriptive NamingDuplication

Page 27: Are You Ready For Clean Code?

SingletonTight Coupling

UntestabilityPremature Optimization

Indescriptive NamingDuplication

Page 28: Are You Ready For Clean Code?

SingletonTight Coupling

UntestabilityPremature Optimization

Indescriptive NamingDuplication

Page 29: Are You Ready For Clean Code?

S OL I D

Page 30: Are You Ready For Clean Code?

Single Responsibility PrincipleOpen/Close Principle

Liskov Substitution PrincipleInterface Segregation Principle

Dependency Inversion Principle

Page 31: Are You Ready For Clean Code?

Single Responsibility PrincipleOpen/Close Principle

Liskov Substitution PrincipleInterface Segregation Principle

Dependency Inversion Principle

Page 32: Are You Ready For Clean Code?
Page 33: Are You Ready For Clean Code?

Single Responsibility PrincipleOpen/Close Principle

Liskov Substitution PrincipleInterface Segregation Principle

Dependency Inversion Principle

Page 34: Are You Ready For Clean Code?

Single Responsibility PrincipleOpen/Close Principle

Liskov Substitution PrincipleInterface Segregation Principle

Dependency Inversion Principle

Page 35: Are You Ready For Clean Code?

Single Responsibility PrincipleOpen/Close Principle

Liskov Substitution PrincipleInterface Segregation Principle

Dependency Inversion Principle

Page 36: Are You Ready For Clean Code?

Single Responsibility PrincipleOpen/Close Principle

Liskov Substitution PrincipleInterface Segregation Principle

Dependency Inversion Principle

Page 37: Are You Ready For Clean Code?
Page 38: Are You Ready For Clean Code?

For Coding Standard ?

…and any Questions?