Possible Duplicate:Ive inherited 200K lines of spaghetti code  what now? I'm dealing with legacy code. It contains some BIG classes (line count 8000+) and some BIG methods (line count 3000+). For one of these methods I wrote a unit test that covers at least some code. This function has no specific structure, it is a mess of nested loops and conditions. I'd like to refactor but still I have no idea how to start.I actually started by extracting one single function. In the end it had to have 21 parameters :-/Should I ...1. continue extracting awful functions knowing that in the long run I will succeed?2. start extracting even bigger functions? So I expose the structure of this monster and then I can start the real refactoring.3. only extract small good functions (and / or classes) just because I am a helluva clean coder?4. do something completely different?
Refactoring several huge C++ classes / methods. How to start?
c++;class;methods;refactoring
Refactoring is somewhat the whole books is written about. It's hard to retell all the methods and pitfalls.Before starting refactoring write the tests for a piece you want to refactor.Start refactoring with small and clean pieces of those big functionsFind the piece that can be rewritten as a function and make it a function.Run tests to be sure you've done the things right and no side effects appearsAfter this you should have and idea what has to be done with all other (big one) pieces.When the whole thing becomes clearer then you can make a higher-level redesign.P.S. it's just a brief sketch. About refactoring itself is better to read some books (like M. Fowler - Refactoring, etc.)