Legacy Coderetreat: Episode 5 – Basic Rules of Refactoring – Code Cast

The book Facilitating Technical Events is for technical trainers, coaches, events organizers who want to have a good event flow and happy attendees.
Support independent publishing: Buy this e-book on Lulu.

Basic Rules of Refactoring – code cast

Blog post series

This blog post is part of a series about legacy coderetreat and legacy code techniques you can apply during your work. Please click to see more sessions about legacy code.

Code Cast

This is a code cast in Java.

We start by checking what can be extracted to another method. The Basic Rules of Refactoring describes the detailed steps I use.

To ensure that we have a safety net, let us start with covering the code with some system tests and then write tests on the newly created method. These are also characterization tests, but they are often simpler than the system tests we wrote before. When the new method have been covered by tests, call it from the initial place where the code was copied from. Run all the system tests. At the end do some manual testing to see that everything works fine.

This technique is very useful to have small and safe steps while refactoring. Remember to never cut and paste. Always duplicate the implementation, cover it with tests and then reroute the call to the new code.

 

 

Acknowledgements

Many thanks to Thomas Sundberg for proofreading this post.

Subscribe

If you want to receive an email when I write a new article, subscribe here:

Subscribe for new articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe for new articles