Creating a Safety Net for Refactoring
Refactoring should make the internals of code better without affecting its external behavior. We’re often eager to reap the benefits of refactoring but have to be mindful of the risks as well. It’s reasonable to worry about the code behaving differently after the change. Due to the hidden complexity in the code, it’s possible that we haven’t fully understood the code we set out to change. Irrespective of how charming the functional style code may look, it’s no good if it doesn’t produce the same results as the imperative style code it’s replacing. Automated tests serve as a safety net for refactoring.
Once we have passing tests, with each change we can quickly verify that the code that worked before continues ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access