Video: No-red refactoring
The more I code, the more I’ve learned to appreciate keeping the code clean even during complex refactorings. By “clean”, I mean that the code always compiles and the test always run.
I often find myself in a situation where I have a method call that’s starting to accumulate parameters. Something like this:
showPersonCreateForm(writer, firstName, firstNameErrorMessage, lastName, lastNameErrorMessage,....);
After three or four parameters, the need to refactor is starting to become evident. I would rather have something like this:
CreatePersonForm form = new CreatePersonForm();
form.setFirstName(firstName);
form.setFirstNameErrorMessage(firstName);
form.setLastName(firstName);
form.setLastNameErrorMessage(firstName);
form.show(writer);
This is one of the more complex simple refactorings you can make, and it requires several steps. In this five minute video, I show how to perform such a refactoring without any steps that break my code:
The screencast was created using the free BB FlashBack Express on Windows. All the magic you see happening while I program is either ctrl-space
(complete) or ctrl-1
(quick fix). Can you modify your code without going thought long stages of nothing working? I think you can!
Comments:
aleksag - Nov 5, 2010
Great post, really cool to see how you can get around eclipses refactoring limitations and do these relatively scary changes safely!
Luis Ernesto Morales Cordova - May 11, 2013
please the code
Johannes Brodwall - May 13, 2013
Here is the starting point before the video: https://github.com/jhannes/java-ee-spike-kata/tree/no_red_refactoring_start