I’m gonna wax philosophic for a moment.
I’m sure you’ve heard the joke that the code you wrote six months ago is always terrible code. It’s a feeling we all share I’m sure.
Here's the thing: It’s not totally true, and the reason it's not true is choice.
When you are writing software you are perpetually making choices. Now, choice is a funny thing because we as humans cannot know the future. We are bound in time. The consequences of our choices are closed to us, as well or ill-informed as we happen to be it doesn’t matter.
Every choice carries with it the potential for good or bad. That’s what a choice is. The part most of us forget though is that good and bad are stupid binary terms that have nothing to do with real life.
You write the code, you make the choice in the Moment of Now. That your code could potentially be a ‘good’ or ‘bad’ decision at the same time is a bit of a paradox, but you have to find the middle of it. Find the eye of that hurricane of decisions, because the alternative is perpetual endless planning and inaction.
Only those who are willing to take the risk of writing code that’s not perfect ever write code.
And your code is never perfect. That’s the nature of it.
So: never doubt or apologize for the code you wrote in the past. And all code you’ve written is in the past, even the code you just finished writing just now.
Accept that you made the choice and you can always make it again when you look at the code tomorrow with more information.
One of the hardest things is when someone else finds a better way to do something that you already did. You just can’t forget that they had the benefit of YOU making the choice. They’re just operating in the aftermath.
You’re never allowed to doubt yourself again is what I’m saying. Or you are, but you simultaneously have to have confidence in yourself.
As one of my favorite authors (Stephen R Donaldson) says, you have to do both and ride the "eye of the paradox".
I'll leave you with a quote from Donaldson about the necessity of freedom:
… are you a person—with volition and maybe some stubbornness and at least the capacity if not the actual determination to do something surprising—or are you a tool? A tool just serves its user. It’s only as good as the skill of its user, and it’s not good for anything else. So if you want to accomplish something special—something more than you can do for yourself—you can’t use a tool. You have to use a person and hope the surprises will work in your favor. You have to use something that’s free to not be what you had in mind.
--Thomas Covenant (in Stephen R Donaldson's The One Tree)