clean code coding like a professional
TRANSCRIPT
![Page 1: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/1.jpg)
Clean CodeCoding like a professional
XPDay Vietnam @ Hanoi May, 2016
Nguyễn Khắc Nhật | Learning Master @ Học Viện Agile
![Page 2: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/2.jpg)
| Agile | Scrum | Kanban | Lean
| Java | Scala | Typescript | NodeJS
| Virtual DOM | Bobril | ReactJS | AngularJS
![Page 3: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/3.jpg)
The snake game
![Page 4: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/4.jpg)
What is the difference?
Good CodeBad Code
![Page 5: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/5.jpg)
Bad code looks like this...
![Page 6: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/6.jpg)
or even this...
![Page 7: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/7.jpg)
Good code looks like this...
![Page 8: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/8.jpg)
or this...
![Page 9: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/9.jpg)
Productivity trend
![Page 10: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/10.jpg)
![Page 11: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/11.jpg)
So...
![Page 12: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/12.jpg)
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
![Page 13: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/13.jpg)
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
![Page 14: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/14.jpg)
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 FeathersWorking effectively with Legacy Code
![Page 15: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/15.jpg)
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 JeffriesExtreme Programming Installed
Extreme Programing Adventures in C#
![Page 16: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/16.jpg)
and...
![Page 17: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/17.jpg)
What make bad or good code?
Names Functions Comments Formats
Objects andData Structure
Error Handling
Unit Tests
Boundaries
Classes System ...
![Page 18: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/18.jpg)
Names
![Page 19: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/19.jpg)
Meaningful Names
![Page 20: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/20.jpg)
Meaningful Names
![Page 21: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/21.jpg)
Naming Rules
Use Intention-Revealing Names
Avoid Disinformation
Make meaningful Distinctions
Use Pronounceable Names
Use Searchable Names
Avoid Encodings
Avoid Mental Mapping
Class Names
Method 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
![Page 22: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/22.jpg)
Try with this code….
![Page 23: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/23.jpg)
and then….
![Page 24: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/24.jpg)
and, how about this...
![Page 25: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/25.jpg)
Functions
![Page 26: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/26.jpg)
Function Arguments
![Page 27: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/27.jpg)
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
![Page 28: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/28.jpg)
Demo with compareTo() method
![Page 29: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/29.jpg)
The beauty of functional programming
![Page 30: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/30.jpg)
Comments
"Don’t comment bad code—rewrite it."
![Page 31: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/31.jpg)
Formats
![Page 32: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/32.jpg)
Formatting
Vertical Formatting
Horizontal Formatting
The team’s rules first!!!
![Page 33: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/33.jpg)
Conventions
![Page 34: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/34.jpg)
Objects andData Structure
![Page 35: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/35.jpg)
Objects and Data structures
Object Data Structure
![Page 36: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/36.jpg)
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
![Page 37: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/37.jpg)
...
![Page 38: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/38.jpg)
Clean, Clean, Clean
![Page 39: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/39.jpg)
Pair Programming
![Page 40: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/40.jpg)
like this …
![Page 41: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/41.jpg)
CodingDojo
![Page 42: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/42.jpg)
CodeRetreat
![Page 43: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/43.jpg)
![Page 44: Clean code coding like a professional](https://reader035.vdocuments.net/reader035/viewer/2022062901/58f11c681a28ab78028b4645/html5/thumbnails/44.jpg)
THANK YOU!