Through early morning fog I see visions of designs to be the features all withheld for me I realize and I can see... Refactoring is painless It brings on many changes and I can take or leave it if I please. I try to find a way to make all our little frobs relate without that ever-present bait but now the project isn't running late, and... refactoring is painless it brings on many changes and I can take or leave it if I please. ... and you can do the same thing if you choose. Apologies to Johnny Mandel... ---- Whew. I just worked through a major refactoring that fixed a long-standing bug in behavior of an object. It was kind of cool: every time I saw that I broke a whole bunch of tests, I backed up to the last "good" version and tried something else. The unit tests steered me into making a string of several painless changes that lead to the correct behavior! Much better than KamikazeCoding... -- MichalWallace It's great when this happens. I think you've just reminded us of a basic tenet of refactoring - that for it to be painless you've got to have UnitTest''''''s. My problem is that I'm currently working on a code review with a company where I've recommended some major refactoring to a project. The problem is they don't have UnitTest''''''s and I have explicitly told them ''not'' to start the refactoring until they have the UnitTest''''''s. So now I have to convince their management to give them a couple of weeks in which ''no new code'' will be written so that they can write the UnitTest''''''s. ''Sigh...'' -- KyleBrown When I am BehindOnMyTests, I write ''some'' UnitTest''''''s before refactoring. Otherwise, I have an excuse to never start refactoring. If things start breaking, I back up and write more tests. (Also, compare this page with SteveMellor's comment that ChangeShouldBePainful) -- KentBeck ---- CategoryRefactoring