Why Clean Code Matters
2020, Aug 07
Code is clean if it can be understood easily – by everyone on the team. With understandability comes readability, changeability, extensibility and maintainability. All the things needed to keep a project going over a long time without accumulating up a large amount of technical debt.
Software defects are introduced when changing existing code. The reason behind this is that the developer changing the code cannot fully grasp the effects of the changes made.
- Writing clean code from the start in a project is an investment in keeping the cost of change as constant as possible throughout the lifecycle of a software product
- Clean Code reduces Cost of Change (CoC)
- Clean code makes it obvious for other programmers.
- Clean code is expressive.
- Writing code for computer is easy, writing code for humans is hard
How to write/make changes in clean code way:
Adopt some simple design principles like:
- KISS Keep it Simple and Stupid
- YAGNI You ain’t gonna need it.
- DRY Don’t repeat yourself.
- Boy Scout Rule: Leave the campground cleaner than you found it.
- Root Cause Analysis: Always look for the root cause of a problem. Otherwise, it will get you again.
- Adopt Coding Standards/Conventions:
- Refactor as soon as possible.
- Don’t reinvent the wheel.
- Adopt some good class design principles like SOLID.
- Reduce Code Smells