Emergence

CleanCode

Next part of my notes from Clean Code: A Handbook of Agile Software Craftsmanship, by Robert C. Martin.

 

 

 

 

emerger

Kent Beck invented four rules of simple design:

Runs all the tests

Our project has to give us a system that works in the intended way. A system that is not tested cannot be verified. A system that is not verified should never be installed.

No duplication

Duplication represents additional work, additional risk and additional unnecessary complexity. We can have duplicated exact lines of code or duplicated context. For example:

int Size() { }
bool IsEmpty() { }

Instead of having separate implementations of each method, we can eliminate duplication by binding IsEmpty with Size definition.


bool IsEmpty()
{
    return 0 == Size();
}

Expressive

Most of the cost of an application is its long time maintenance. Code should express author’s intentions. How to achieve that? We can choose meaningful names, create small functions and classes, use design patterns and create unit tests.

Minimal number of classes and methods

On one hand functions and classes should be small and on the other hand we should not create too many classes or functions. For example having an interface for every class is not necessary.

References

“Clean Code: A Handbook of Agile Software Craftsmanship” – Robert C. Martin

Leave a comment