Chia sẻ về Clean Code tại XPDay Vietnam 2016.
Clean Code là gì?
Tại sao phải Clean Code?
Clean Code có khó không?
Một số ví dụ thực tế về áp dụng Clean Code.
12. What is clean code?
“Clean code is simple and direct. Clean code
reads like well-written prose. Clean code never
obscures the designer’s intent but rather is full of
crisp abstractions and straightforward lines of
control”
Grady Booch
Object Oriented Analysis
13. What is clean code?
“Clean code can be read, and enhanced by an
developer other than its original author. It has unit
and acceptance tests. It has meaningful names. It
provides one way rather than many ways of doing
one thing. It has minimal dependencies,...”
Dave Thomas
OTI, Eclipse
14. What is clean code?
“I could list all of the qualities that I notice in clean
code, but there is one overarching quality that leads
to all of them. Clean code always looks like it was
written by someone who cares...”
Michael Feathers
Working effectively with Legacy Code
15. What is clean code?
“In recent years I begin, and nearly end, with Beck’s
rules of simple code. In priority order, simple code:
Run all the tests;
Contains no duplication;
Express all the design ideas that are in the system
Minimizes the numbers of entities such as classes,
methods, functions,...”
Ron Jeffries
Extreme Programming Installed
Extreme Programing Adventures in C#
21. Naming Rules
Use Intention-Revealing Names
Avoid Disinformation
Make meaningful Distinctions
Use Pronounceable Names
Use Searchable Names
Avoid Encodings
Avoid Mental Mapping
Class Names
Don’t Be Cute
Pick One Word per Concept
Don’t Pun
Use Solution Domain Names
Use Problem Domain Names
Add meaningful Context
Don’t Add Gratuitous Context
27. Function Rules
Functions Should be Small
Functions Should Do Only One Thing
One level of Abstraction per Function
Use Descriptive Names
Function Arguments
Have No Side Effects
Command/Query Separation
Prefer Exceptions to Returning
Error Codes
Don’t Repeat Yourself
Multiple Returns
36. Law of Demeter
Given method ƒ of class C, ƒ should only call methods of:
● C
● An object created by ƒ
● An object passed as an argument to ƒ
● An instance variable of C