Either refactor it or throw it away and start over.
In either case, try to take things one "story" (use case) at a time, building and testing small increments, and refactoring the code when you're done. Refactoring is like cleaning the kitchen when you're done cooking. It leaves less places for bugs to hide, and sets you up for a clean start for the next meal.
The key to making this kind of development work is having an up-to-date test suite. Otherwise, you're never quite sure if you broke something.
If I step into a mess, I'll try to write some test cases before I start to refactor. Often, the simple (hah!) act of getting tests cases running is enough to uncover substantial problems.
In reply to Re: What to do when you realize you've written bad code
by dws
in thread What to do when you realize you've written bad code
by l2kashe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |