Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Any tips for dealing with the anxiety of having written bad code?
4 points by Trasmatta on Dec 27, 2022 | hide | past | favorite | 10 comments
It at least solves the defined problem, is performant, secure, decently tested, and stable. So you might call it "good code" by those measures. But there are some glaringly bad, overly complicated patterns that make it unnecessarily hard to understand and very difficult to work with and build on top of.

I've been feeling a lot of anxiety from this. It's affected my sleep, even during vacation. I'm waking up in the middle of the night thinking about it. I've been nearing burnout for a lot of reasons recently, and I worry this could push me over the edge.

I think the main anxieties stem from:

* Not being able to have pride in my work, which is undermining my confidence. It's always been important to me to feel good about my work.

* Fear of how this code will bite us in the future.

* Feeling shame around my peers. It makes me feel really dumb around smart devs that I like and respect. (I almost feel like crying while writing this out.) I have already heard rumblings from team members about how bad certain things are, and it makes me feel stupid and incompetent. It hasn't been their intention to shame, but it still hurts because I agree with them. But they don't have a full understanding of all the many factors that led to this.

There are a lot of reasons this happened (including some poor early decisions that I'll take full credit for, a complex and changing feature set, pressure to hit a hard deadline, building on top of an existing codebase with many legacy issues, team politics, and concurrent personal issues), but those are the things nobody sees when they look at a git blame.

I've got 10+ years of professional experience, so I've shipped plenty of substandard code and been through all of this before. I know a huge portion of code in the world is bad, and this should all be old hat by now. But it's still never caused as much internal angst as this.

Some possible paths forward I've been thinking of:

* Just make the code better - I can do small bits progressively, but a major refactor has been shot down by leadership at this point in time. And the undermining of my confidence is filling me with the fear that I'm not even capable of this. Maybe if I can just slowly keep getting small wins over time I can build my confidence back up.

* Documentation - for the things I can't fix, at least document what the current state is, to provide help and background for future developers.

* Therapy - I'm already in therapy, and will bring this up. There are some obvious "self worth" issues tied into this, with me attaching my worth as a person to the quality of my code. Maybe my therapist can help with this.

* Stoic exercises - I can't change what others think about me or my work, so I can try to not let it bother me. (Easier said than done. Stoicism has never worked super well for me.)

* Find a new job - maybe I just need a new perspective and a fresh codebase. (This would be a challenge right now.)

Would love any advice or similar experiences HNers might have!



You already enumerated the reasons this happened, many of which were beyond your control. Just keep that in mind when you're writing the documentation you were considering. It will explain your thought process as a developer, and as a bonus it will help cover your ass when whiny engineers (and managers) begin to pick at your code choices. Heck, even just writing the documentation and having it in your back pocket will help you feel better, even if nobody ever sees it.

Document everything over time, so you can show why you did "X" before you were told about "Y". Also document that you offered to do a rewrite but were rejected. Don't be afraid of naming names--not in a vindictive way, but very matter-of-factly.

Engineers love to whine about other engineers' code, especially when they don't understand it, regardless of how well or poorly it was written. Ignore the haters. Ironically, it's the ones who complain the most who usually know the least.

If your code works, there's probably little chance anyone will authorize any kind of incremental rewrite since a) it costs money (your time), and b) it will require testing (again, more money/time). Don't sweat it. Your code will join the huge, largely unseen iceberg of substandard code that underpins just about every project in the world. Welcome to the club!


Is it genuinely bad code, or code written under limitations? Plenty of great developers and engineers code things poorly when either under a time crunch/stretched for time, with a limited budget, with dozens of other things on their plate, based on manager suggestions, when tired/burnout, etc. Maybe it's just the best that was practical within the current situation or based on what you knew at the time. No need to beat yourself up about that, everyone ends up in those situations.

Also worth thinking less about how it affects you, and more about how the customer/client/users feel about the work done. Do they appreciate your efforts? Are they happy with the work you've done? If so, you can look on the positive side there and say that you made someone else's life better, even if you're disappointed in the specifics of the way you achieved that.

Plus if you keep thinking this way, you're gonna get more and more depressed in future, since there will always be code you're not proud of and feel could have been written in a better way. You shouldn't be treating this as a reflection on yourself, especially not when it's likely a product of the circumstances and appreciated by those you work for/with.

As for what you can do going forward... I guess all of that stuff? Gradually refactoring small parts can work, though you may want to leave it a bit and come back in future. Documentation will always be useful, especially if you explain why you made the decisions you did, and how it could be improved. And therapy is probably important here for sure, if you're tying your self worth so heavily to your work.


Thank you for the reply, this helps!

> Is it genuinely bad code, or code written under limitations? Plenty of great developers and engineers code things poorly when either under a time crunch/stretched for time, with a limited budget, with dozens of other things on their plate, based on manager suggestions, when tired/burnout, etc. Maybe it's just the best that was practical within the current situation or based on what you knew at the time. No need to beat yourself up about that, everyone ends up in those situations.

Definitely written under a lot of limitations. It was a large feature with a difficult time crunch, and very limited dev resources. I did make some poor decisions early on, too, but I do feel that I did the best I could.

I think the major part of my current anxiety is really the "feeling stupid and incompetent around other developers on the team" thing. Especially the ones who will have to build on this thing in the future. So I can forgive myself for not being perfect, but I'm still sitting with a feeling of shame and incompetence.

When I talk with other devs and they mention how we should have done things a different way and that the current pattern is bad, I get two major thoughts / feelings:

* "They're totally right, and I really am fucking stupid"

* "They don't understand the pressure I was under or the context in which those decisions were made, and it makes me a bit angry to have my work judged harshly without knowing what it was like to be put through this"

> and more about how the customer/client/users feel about the work done. Do they appreciate your efforts? Are they happy with the work you've done?

Thanks for the reminder, they are happy with it! That's something to be proud of.

> You shouldn't be treating this as a reflection on yourself, especially not when it's likely a product of the circumstances and appreciated by those you work for/with.

Thanks for this reminder as well. I know I shouldn't treat it as a reflection on myself, but it's hard to convince my brain not to. Something to get help with in therapy I guess.


I can do small bits progressively, but a major refactor has been shot down by leadership

Why? Ask. Maybe it solves problems well enough and maintenance costs are low enough that they'd rather you were contributing to Y instead of reworking X to be better for programmers but not have a noticeable impact on the bottom line. Understanding where that functionality fits into the business model will probably help you understand the development constraints better and worry less about the issue. It might also indicate that the management are being shortsighted or not really listening to feedback from their engineering people.

If you hear a negative comment from someone else, it's good that you realize it's about the problematic code rather than you. You could (again) ask how they'd approach the issue, given that you can't get resources to cover the cost of a refactor. Maybe they can team up to persuade management? Or maybe they can suggest a way to get it done faster. Maybe you can prototype the better version and then use that to change the suits' mind. Meantime, if your fellow team members don't have a full understanding and they are not the ones who had to land the plane, then you should discount the weight you assign to their approval.


- Real products get cruft. Developers always complain about the state of things.

- Everybody writes bad code, and you learn and get better as you go along. If something is bad and you can see that and take responsibility, that sounds good, and it sounds like you have learnt and become better. You don't need excuses like "personal issues".

- You aren't always going to be as smart or good as your colleagues, sometimes you just have to come to terms with that.

- Major refactors of a product are rarely the right way to go. If you can do it progressively and gradually that is almost certainly the better approach.

- Almost zero percent chance you will find a "fresh" codebase in any new job. A change can be helpful, but it doesn't change yourself.

Good luck with it. Happy New Year.


> You don't need excuses like "personal issues".

For what it's worth, that was not an excuse I would give to anybody on the team, but just an honest look at one of the underpinning factors that I can more easily bring up in an anonymous forum. I can do better than I did, but I was barely keeping it together mentally for large portions of this year.

> Almost zero percent chance you will find a "fresh" codebase in any new job

I mainly meant fresh as in "fresh / new to me", rather than "fresh / pristine" codebase (which doesn't really exist).

> Good luck with it. Happy New Year.

Thank you!


I wasn't trying to say that was invalid or made up that you were going through those difficulties and I'm sure it can impact work. My point was more that I don't think it's helpful to consider it a failing due to factors out of your control. If your old code sometimes makes you cringe or think of various things that you would have done differently and better, that's evidence that you've been learning and improving. It's healthy for everyone to feel that sometimes and be able to reflect and critically evaluate their own work (though maybe not to the level that you're taking it).


Sometimes circumstances demand you do a sub-optimal or even sub-par job of things. I like the quote from pulp fiction "you might feel a slight sting: that's pride fucking with you. Fuck pride."


That quote is great, thank you.


I take solace, maybe ignorantly, that everything made by humans is inherently imperfect, and that nothing burns down and nobody dies if my code or whatever sucks more than my peers' code. Also, if someone thinks my stuff sucks, they can snicker at it, or they can help with a better idea. It seems to me that software is all about ideas that build upon or replace each other.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: