How do you deal with your past programming atrocities?
language-agnostic
Solution
No regrets. If you're not ashamed of the code that you wrote last week that means that you've not improved as a programmer ;-)
Seriously though, my approach has always been to fix stuff that's dangerous (SQL injection vulnerabilities for instance) with urgency and then to refactor other code ugliness if and when I happen to be working in a particular area that needs refactoring. When fixing bugs or introducing new features I often keep a list of bits of code that require refactoring and then refactor the code after I'm done with my 'real' task. It usually doesn't take an inordinate amount of time to do and I have unit tests to make sure I didn't break anything (if your code is not unit tested, this is a great reason to get it tested!).
Jeff Atwood wrote a great blog post on this some time ago (here).
Problem
None of us started off as experts (and most of us still aren't). Sure, we all knew how to write programs in our preferred languages, but writing quality applications and writing syntactically correct programs are two very different things. We work, we learn, we struggle, we keep learning, and eventually we reach that threshold where others can learn from us. If your learning process was anything like mine, you probably wrote a few perfectly functional, reliable applications that are still used daily, yet can't help but drop your head in shame whenever you think about them. Procedural code? Mixing business and presentation logic? SQL injection vulnerabilities? Wastelands of code barren of any comments? The list goes on. Unfortunately, none of us can expect our employers to allow us to go back and rewrite our old applications just because they give us nightmares whenever we think about them. Worse, some of us have to actually work with our old applications, but know that it would be way too risky and/or time consuming to do a whole lot of good as far as refactoring goes. How do you deal with the past programming atrocities you've committed and with the people who discover the dirty secret that you didn't always know what you were doing?