THE SECRET RELIGION OF THE DEVELOPERS
đ REFACTORISM đ
Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal structure.
â Martin Fowler
As far as I remember, I considered myself as a refactorian (a developer who believes in refactorism). Actually, it took me several years to get here. I arrived after hours and days of refactoring legacy code, refactoring workshops and pair programming with some of the best refactorians I had had the pleasure of working with. I finally left behind my annoying fear of âitâs gonna blowâ that every developer feels when starting to refactor.
The excitement of transforming spaghetti code into clean code without changing its functionality, playing with all the moving parts all together until everything fits in like magic, is something that always motivated me. I wonât lie to youââârefactoring is hard work, however, itâs definitely pays off.
If It Ainât Broke, Donât Fix It.
â Anonymous Loser đ
When do you need to refactor your code?
Rule #1:
You donât decide to refactor, you refactor because you want to do something else and refactoring helps you to do it.
Rule #2:
The first time you do something, you just do it. The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor.
â Don Roberts
Why is refactoring important?
- Makes code more readable, easier to understand
- Cleans up code and makes it tidier
- Makes code more maintainable
- Makes it easier to add new features
- Removes redundant, unused code and comments
- Improves performance
- Makes code more generic
- Keeps code DRY (Donât Repeat Yourself)
- Creates reusable code
- Better class and function cohesion
- Makes your code testable
Some Tips before you startâŚ
- Do it gradually!.
- Always start from green â (test passing) and end in green â . Otherwise, youâre not refactoring.
- If itâs not going well, take a deep breath, roll back your changes and start over.
Now, if you are a true believer đ, start refactoring and happy coding!