Basic Code Design
- inspecting production incidents leads often to reading code which is not good designed
- avoiding technical debts in the future ($)
- you build it, you run it
- no bashing
- continuous learning/improving
- more fun and time for the important things
Patterns in our codebase
- tight coupling
- no space to move
- Single Responsibility
- Liskov Substitution
- Interface Segregation
- Dependency Inversion
- Law of Demeter
- A class should be responsible for only one thing
- everything in the class is highly related to its purpose
- enforce this everywhere (functions, services)
- "What does a Mr. Function do?"
- BAD: computes that AND that AND that AND AND that AND that AND that ...
- GOOD: no AND
The purpose of software engineering is to control complexity, not to create it.
- Why it matters:
- code is easy to understand (wow)
- encourages code reuse
- code can be tested
- code can be easily refactored
- no need of comments
- please stop writing comments, write functions instead
- classes, modules and functions
- should be open for extension
- should be closed for modifications
- subtype should be replaceable for the supertype without altering the correctness
- violation of Liskov Principle violates the Open-Closed Principle
- many client-specific interfaces are better than one general-purpose interface
- it's all about abstractions and decoupling
- high-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.
Law of Demeter
- Only talk to your immediate friends
- Don't talk to strangers
- It's a design smell
More from the kitchen
- Always go for the most simple solution
- at the third refactoring you have it
- Deep hierarchies are evil
- nobody understands them
- Don't reinvent the wheel (know what's there)
- don't write own monitoring systems or
- own build tool or
- own stress testing tool or
- the new Spring-Framework or
- own HA-Tools ..
- Adopt design patterns
- every week one can present a new pattern in his favorite language
- If you think you need more time to implement the feature better, say it and fight for it.
- Java/Js best practices every week
- Open-Source projects
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
Basic Code Design
By Stoyan Stoyanov