Clean Code Approaches
Simple Design / Emergent design
Author: Kent Beck
Runs all the tests
Contains no duplication
Expresses the intent of the programmer
Minimizes the number of classes and methods
Perfection is achieved, not when there is nothing left to add, but when there is nothing left to remove. (Antoine de Saint-Exupery)
Pseudo code
The code should look like a pseudo code
The types and methods and names we create are pseudo code really
DSL - Domain Specific Language
The business analyst should be able to understand it
Example: Pseudo code
Example: Good: Java code
Example: Change request
Example: Good: Changed code
Specification vs. Implementation
Specification: Name or description or "contract" or "promise" = class and method declarations
Implementation: "internal part" that fulfills the promise = code block {}, package content, etc.
Every code unit is a "separate world" - e.g. class or method blocks
What does this code do?
The reader will ask it
The developer should ask it
Metric Rules
There are NO numeric rules like maximum lines of code, number of parameters, level of indentation, etc.
The only numeric rule is: One code does one thing + One thing is implemented once
Classes and methods should be "small" but it is not exactly defined
Developers
Do not only satisfy the compiler or the unit tests
Be the reader of your own code - stop and think
"Tell the story" with proper types and names
Describe the business logic with English words as much as possible
Avoid "Enemies" of the Code
No duplication - DRY
No inline implementation
No misplaced code
No parallel development - "spaghetti code"
No unused code - "dead code"
Clean Code is an Art
Not a set of mechanical rules
More principles to apply
Continuous thinking and shaping the code - "step back"
Scrum
"Code is clean"' should be part of Definition of Done
Last updated