<p>Do you refactor your SQL first? Your architecture? or your code base?
Do you change languages? Do you throw everything away and start from scratch? [Not refactoring]</p>

[{'answer_id': 66391, 'author': 'Anthony Mastrean', 'author_id': 3619, 'author_profile': 'https://Stackoverflow.com/users/3619', 'pm_score': 1, 'selected': False, 'text': '<p>This really depends on the state of the codebase... are there massive classes? one class with mega-methods? Are the classes tightly coupled? is configuration a burden?</p>\n\n<p>Considering this, I suggest reading <a href="https://rads.stackoverflow.com/amzn/click/com/0131177052" rel="nofollow noreferrer" rel="nofollow noreferrer">Working Effectively with Legacy Code</a>, picking out your problems, and applying the recommendations.</p>\n'}, {'answer_id': 66763, 'author': 'interstar', 'author_id': 8482, 'author_profile': 'https://Stackoverflow.com/users/8482', 'pm_score': 4, 'selected': True, 'text': '<p>I\'m adding unit testing to a large, legacy spaghetti codebase. </p>\n\n<p>My approach is, when asked to solve a problem, I try to create a new wrapper around the part of the code-base which is relevant to my current task. This new wrapper is developed using TTD (writing the test first). Some of the time calling <em>into</em> the non-unit tested legacy code. At other times I make a new copy of an existing module and start to do serious violence to it. Sometimes I rewrite functionality from scratch. </p>\n\n<p>But as I\'m keeping it fairly well tested I feel pretty in control.</p>\n\n<p>What I find with this code-base, which has been developed with far too much copy and pasting, is that once I get an understanding a particular part, and extract some functions from it (which are done test-first) ... these functions often turn out to be usable in many other places and so the rate of replacing the legacy code with my own, unit tested libraries increases.</p>\n\n<p>I don\'t (and have no authority to) try to rewrite or add tests to parts of the code that are not touched by my current problem (usually a bug I\'m trying to fix) but I do have a fairly aggressive proactive stance on anything that is touched and might be relevant.</p>\n\n<p>Update : Penguinix asked : "What languages do you work in? Is there a specific Testing Harness you recommend?" </p>\n\n<p>Right now I\'m working in ... er ... Mumps! But the same principle works anywhere. </p>\n\n<p>Something that transformed my understanding of UT was MinUnit : <a href="http://www.jera.com/techinfo/jtns/jtn002.html" rel="nofollow noreferrer">http://www.jera.com/techinfo/jtns/jtn002.html</a> </p>\n\n<p>When I saw MinUnit, that was kind of a "zen" moment of enlightenment for me. It stripped away the misunderstandings I had about unit testing being something complicated requiring sophisticated OO frameworks etc. I understood that UT was just about writing a bunch of tests. The "harness" you can write yourself, in about 3 minutes, in any language you like. Just get on and do it.</p>\n'}]
['https://Stackoverflow.com/questions/66361', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6943/']