3 ms·
Always. The development cycle should be Test, Code, Refactor, as one atomic block of work. Sarah Mei explains why this is vitally important to creating good cod
by jameskilton 13y ago
Always. The development cycle should be Test, Code, Refactor, as one atomic block of work. Sarah Mei explains why this is vitally important to creating good code in her talk "Work, Play & Code", I highly recommend checking it out.
http://confreaks.com/videos/2333-mwrc2013-work-play-code http://confreaks.com/videos/2333-mwrc2013-work-play-code
Also, if you don't have a test suite to prove your refactoring didn't change functionality, IMO you aren't refactoring, you are simply rewriting. This is the point many people miss about TDD. TDD is first and foremost about letting you refactor your code; doing TDD right gives you the best environment for writing great code. On the other hand, doing TDD wrong makes it more likely your entire code base will be very difficult to maintain.
- InclinedPlane 13y agoOne advantage of TDD is that encourages your code to be more easily testable. Which tends to encourage you to develop properly modular code. Code that can only be tested indirectly through integration testing (spinning up huge unwieldy hunks of context that are required for the individual sub-component to work properly) is not very modular. Modular code tends to have fewer dependencies and tends to produce fewer side effects. All of these things make for code which is generally easier to maintain and modify, easier to understand, easier to debug, and easier to reuse. All of which tend to lead to higher code quality naturally. A high level of unit test coverage also gives you other benefits, of course, but I thought I'd highlight these side benefits because they are perhaps the most important.
- drharris 13y agoThis, exactly. You should always be looking to improve code. If you have a truly comprehensive test suite, there is no danger in always improving code. It's easier to make refactoring continuous than it is to figure out a checklist of when to do it. The answer is "always".