I'm a programmer, like many of you. I'm 31 years old, working as team lead where I luckily still get to do lots of coding.
On days where I do well at my job I feel good, optimistic and motivated in my life, including non-work related activities.
Unfortunately the same is true when I don't have a productive day. It makes me feel depressed, worthless, unable to plan ahead and unable to look at the positives in life.
How do I learn to separate the two? I think I have a good work-life balance, but work seems to disproportionately affect my mood. On a day where I can't solve a bug or my progress is slowed down due to some distraction, I feel like shit and I can't seem to shake it off.
You seem to be defining your self-worth as your performance at work. At work you are simply a replaceable employee, whether you do well or not is defined by a bunch of managers and higher ups at your job. Why are you letting them define your self-worth? I'm pretty sure you are worth way more than that. Define your self-worth yourself don't let others decide, there is more to life than work.
Meditation and/or exercise. It's very human to ruminate over a negative experience. Both meditation and exercise can help refocus your mind on more important things.
Divest in your job. Find other things to do that you care about.
Sounds corny but this book has a lot of practical advice on how to process emotions and build healthy habits. It’s written by a psychologist and it’s a lot of CBT with explanations of the stoic origins of the current recommended CBT practices. Helped me out.
https://www.amazon.com/How-Think-Like-Roman-Emperor/dp/12501...