
TDD as if you Meant It: Refactor and Clean-Up (Episode 11)
About
From Wikipedia we learn that
Code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior
So clearly not any change in the code is refactoring.
During the last few episodes I extracted many design elements from the initial primitives, and this was refactoring.
Refactoring is different than clean-up. When cleaning I care about Clean Code, Coding Standards, Clarity, etc. Refactoring is difficult to make when I don’t have Coding Standards, because the duplication is more difficult to spot.
So my recommendation is
Every once in a while clean-up the code so that you can refactor your design easier!
Refactoring
The refactoring approach during this episode is mainly focused on design. There are many reasons to do refactoring: improve clarity, design, minimize defects, exploring alternatives, etc. These are the final stages in the TDD as if you Meant It cycle, when the design elements are almost ready to be separated completely from the tests.
Clean-Up
Cleaning up is important every once in a while. Without a clean code we cannot focus on the essentials, because there is too much mess. By clean-up I mean deleting the unused methods, delete the useless comments that initially were important, having the same structure in the same place, etc.
I really like having classes look the same: constants at the top, fields, constructor, public methods, private methods. And also having always the same spacing between methods, parameters, etc. All these have to do with the coding standards I use.
Coding standards are useful because they let me focus on what I need to refactor. I can easier see duplication between classes if they are structured the same.
Video
Check the video below with the codecast:
What’s Next?
Check the next episode on TDD as if you Meant it here: http://blog.adrianbolboaca.ro/evolutionary-design
On the same page you can find more ideas on Evolutionary Design.
Credits
Many thanks to Keith Braithwaite for creating the concept of TDD as if you Meant It
Teddy bear thanks to Erik Talboom for all the pairing, discussions that lead to so many twists we discovered together with TDD as if you Meant It.
Special regards to JB Rainsberger for the fun pairing we did using TDD as if you Meant It
