This week, I'm deleting lots of my code.
This is actually a pretty common occurrence for me. In this case, a UI pattern that I came up with for a project works well in the small, but doesn't scale up. Other times, I've worked on a chunk of code and revisited it enough times that its structure was no longer clear, and the cognitive effort of remembering all its inconsistencies significantly outweighed the benefit of keeping it. Every once in a while I'll have thought of a better way to do something, and it's worth replacing the old code with a new implementation of existing functionality. One manager I had was increasingly perplexed with my weekly announcements of having less code. When he finally asked, I pointed out that having a small amount of the right code was much better than lots and lots of the wrong code.
I think that as developers we often have a hard time deleting code. Every line of code represents an investment in time and effort, possibly by many people. Deleting any of it can seem disrespectful. A lot of times it seems like we can just add a little bit more code--take care of some edge cases, extend the class hierarchy, add a few accessors--and the everything will be all right.
It probably won't.
I think it's unfortunate that so much effort goes into patching and extending code that really ought to have been learned from and discarded, but making that determination is tricky. If a piece of code runs well, but is ugly, are aesthetics a sufficient reason to rewrite it? Partially working code is better than nothing, maybe, and I know I can't add bugs if I don't write anything. Can we really estimate the effort to work around buggy code and accurately compare it to the cost of a rewrite?
At the very least, if I'm going to delete something, I do it wholeheartedly. I think it's better to keep the lessons rather than keeping any of the code, and I know I can always produce more code. Sometimes, though, it'd probably be better to hold off writing anything until I'm reasonably sure I'm not just going to delete it later.