How do you deal with bugs psychological and technicaly?

Hi , today and yesterday not only I introduced 2 bugs in the code but also I failed to find them quickly enough
the thing that bothers me is this , why didnt I see it ? it was just a simple if statement , but my mind went to more complicated stuff that might have failed and could nt see in front of me, so now I am beating myself cause I am too dump and very sloppy to be a good programmer ever

That happens to me very often.

Why didn’t you see it? It’s because you have other larger things in your development to address. Looking at thousands of lines of codes all day, every day can be brain-numbing.

Be glad you caught this easy bug, and that it was an easy bug before it’s too late. This surely saved you an unnecessary headache down the road.

Don’t be so hard on yourself. We all make mistakes like that.

Every time you update something in your code, you might introduce a new bug. That’s just the way it is.

That’s why it’s important to have automated testing. Look into how you could improve your development process by introducing unit testing and continuous integration.

I think that’s the whole secret in software development. Thank you @monkeypatching, In my opinion you are absolutely right.

Q:How I deal with them technically?
A: Our industry has developed - no pun intended - patterns and tools how to deal with the adversities. If you use them you’re on a good path slashing those evil bugs. But be aware, there will still be some bugs.

Q:How to deal with them psychologically?
A: Well, zen like acceptance and calmly using the technical tools I have at hand. Those tools are log files, version control, debuggers, differs, unit tests, data analysis. But there are also psychological tools, in my opinion those are acceptance + intuition + agnosticism.

I think I need to explain what I mean with acceptance + intuition + agnosticism. I don’t mean just the plain old gut feeling we have. I also mean being able to decide if the gut feeling might be right, not focusing on the bug’s existence and …

…too woo-woo? Well I think I need to give an example…

Example

You know those “_Oh, no, can’t be…”, “I didn’t change anything…” or “It worked yesterday.” moments? If this happens, my thoughts are “I do know nothing besides the fact that the code breaks.”.

Acceptance: You have two possibilities. #1 stay calm and accept the bugs existence or #2 focusing on the fact ‘you didn’t change anything’. #2 is like sticking your head in the sand and pretending the bug popped only into existence to make your life worse. #1 is the right decision, you no longer focus on how bad your day is but can start to think about the real problem.

Intuition + Agnosticism: If the logs don’t show anything, the tests pass and you still have the bug and checked that really nothing was changed (diff tools, version control, etc.) then it might be a temporal problem (maybe some hard coded dates, date/time boundaries of some kind), differences in environments (dev vs. prod), dev-ops changed something or you checked the wrong things until now. If you did not find the cause, do not switch back on the ‘I didn’t change anything’ thoughts - be like an agnostic, know that you do not know (now). Take a break, ask for your peers opinion. Seriously, write down and log the whole bug searching session, note anything you already checked, the outcome of your checks, etc.

It’s all about staying sane and not getting upset. I hope I didn’t waste your time.