You are not your code

One of our primary functions as developers is to write code. It's what we'll naturally spend a lot of our days on - writing code, optimizing it, fixing bugs, refactoring etc. That's why we can sometimes get a bit too attached to our code. The more time we spend on code, the more it can feel like a part of our identity.

But that can be dangerous.

The more we get attached to our code, the harder it becomes to take feedback. It becomes harder to stay objective and realize when our code could be written in a better, smarter way. Every correction or comment from a peer can feel like an attack on us, even when it's almost never meant that way. And if our code doesn't pass code review, it can feel like we failed.

That's why it's important to deal with this mental barrier. You need to switch your mindset, because someone criticizing your code has nothing to do with your person, and definitely does not reflect on your character. Your code does not === your identity.

Instead, try to see feedback as an opportunity to grow. When you think about it, having someone point out your flaws, while uncomfortable, can be a godsend. And if someone (or yourself) finds a bug in your code, that just allows you to cover a gap in your mental model and improve your skills.

Some code you write will be good and some will be bad. The key is not to get stuck on the bad parts - just learn from it as much as you can and then move on.

Life is easier that way.