Early on, I noticed:
(1) There is actual reality.
(2) There is how you feel, your emotions.
While (1) and (2) can affect each other, the connections are weak and indirect, and, mostly, first cut, (1) and (2) are independent.
So, for things like doing well in some school work, getting a car repaired, having a good romantic relationship, getting the bank balance up, having money enough to buy a house, losing weight, ..., nearly all that is (1) and not (2).
Good news: If you get all the bugs out of some computer program, then the program will run the same whether you are feeling good or bad. That is, no matter how bad you feel, the program doesn't care and will run the same anyway. Sooo, that situation is a way to make progress in (1) even if are not doing well with (2), and that progress might help you do better with (2).
As an experienced programmer, you really CAN get the bugs out of that code and have the code run, no matter how bad you feel -- progress in (1) is right there, available to you, and it is sufficient for you just to get the bugs out of that code!!!
Uh, that you are able to write this query and post it here on Hacker News puts you way, Way, WAY ahead of maybe 80+% of the people alive today and 99.9+% of the people who have ever lived. A lot of those people were really happy, had good lives -- it's possible and has happened for many millions with much less in advantages than you have.
Uh, for romantic relationships, I tried to understand what worked, what didn't, and why. I settled on -- interruption, not everyone will agree -- one that works is driven heavily just by Darwin, and he wants (i) emotions, (ii) sex, (iii) pregnancy, all QUICKLY, and then return to (i) and do it all over again several times. If Darwin is disappointed, the relationship is on thin ice. In particular, please Darwin or don't be surprised to have the relationship fail. Sorry 'bout that.
A lot of things -- plans, activities, efforts, etc. -- are necessarily chancy. When trying such a thing, insist that it work, fairly well fairly quickly, or abandon the effort and try something else. That is, it's too easy to have lots of reasons why the effort really SHOULD work and, thus, continuing, for weeks, ..., years, decades trying to make the effort work. Fact of life: We don't know everything that is important; we don't understand all the details; we are really NOT in actual control. So, we give a good shot; if it works, terrific; if it doesn't, drop it and try something else. And by "give a good shot", don't bet too much; don't bet the farm; hopefully don't bet more than you can afford to lose.