Re: Ambiguous Refactoring Solution
Adam Sroka <[email protected]>
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Sep 24, 2009 at 8:57 AM, joshua <[email protected]> wrote: > > > > > > > It's true that we 'occasionally' have to resort to doing a particular > > refactoring without the benefit of a test. I would guess that you've come > > across this idea from reading Feather's book, where he discusses 'seams'. I > > think he made the point, that it's rare and comes about when you can't > > figure out a reasonable way to write a focused test first. I can count the > > times I've had to resort to that; it would be sloth on my part if it > > happened more often. > > > > Hi Hal, > > I'm not so sure. Some folks I respect a good deal recently encountered > legacy code that was really poorly designed. They knew how to write tests > for it. Yet they felt that writing such tests would only couple the tests > to a very poor design. They decided to refactor first, sans tests, manually > test that all was ok, then write the tests against the newly refactored. I > think that was likely a sensible path to take in that situation. > I think we're talking past each other (as usual.) Is it generally good advice to refactor untested code? Without sufficient context, is this something you would recommend? The context we were given was: A 600+ LOC module in C++, which is "reasonably cohesive" but has at least two distinct responsibilities. It consists mostly of very small methods. It is not tested. It is not reused anywhere. That is everything we know about this class. Given that, is it reasonable to assume that not writing any tests would help to improve the design of this code? I know that people sometimes regard me as a zealot, and that is not entirely unjustified. However, the only justification that I have heard for not testing this code is that, "people do it all the time," and that is not sufficiently moving. I will stick with my "idiomatic dogmatism" in this instance, because I am reasonably certain that writing tests for this class would be the most beneficial thing you could do next. On the other hand, I will concede that there could be circumstances where writing tests was too expensive in the short term. Is there any reason to believe that this is one of those times? ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/refactoring/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/refactoring/join (Yahoo! ID required) <*> To change settings via email: mailto:[email protected] mailto:[email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/