DEV Community

Carl Anderson
Carl Anderson

Posted on • Originally published at on

Bad code isn't shameful

Let's be honest. We all write bad code.

Sometimes, we write absolutely shocking code.

In the programming community, we have an obsession with "good" code – and it's not difficult to see why. Good code is objectively better than bad code. It's faster, cleaner, more maintainable – Why would you settle for anything less?

Because we can't always write good code – Sometimes there isn't time. Sometimes there's legacy code. Sometimes the code was good when we wrote it, but the requirements changed.

Sometimes we just don't know how

Good code is an ideal – something we should all aspire to, but bad code is a part of life. Writing bad code isn't shameful. Writing bad code doesn't make you a bad developer.

The only thing that's shameful is never trying to write good code at all.

Discussion (5)

adaddinsane profile image
Steve Turnbull

Speak for yourself, matey boy :-)

Those things you describe? They aren't my code.

Since I know requirements will change (and clients will always want more), I write code that is open and extensible so future changes can be incorporated with the minimum of disruption and without breaking anything.

I've worked with the most atrocious legacy code on sites pulling in a million quid a day ... I still didn't write bad code. I refactored and built new structures.

So no, you don't have to write bad code, ever.

jpalvis86 profile image
Juan Pablo Alvis

I read this several times trying to understand your point because I do feel we shouldn't accept bad code, I know we can't always write good code but the first time I read this I got some sense of tolerating/justifying bad code in which I disagree completely.

Some things to consider:

  • Sometimes there isn't time: Strive for having more time the next sprint/project to make it good from the start or add a TODO to improve it later.

  • Sometimes there's legacy code: Make it better at least a little bit.

  • Sometimes the code was good when we wrote it, but the requirements changed: Good code should be flexible and maintainable to allow changing it without too much pain. If there's anything worse than writing bad code, it's worsening good code.

TL;DR: We can't always write good code, but we should strive for it and if we don't feel bad for doing it badly, then it will never improve.

rinsama77 profile image

I feel like some people don't fully read your post. O agree that writing bad code isn't shameful, people make mistake all the time and that shouldn't be marked as shame. What's shameful is, just like you said, that you never try to improve or make it better.

baso53 profile image
Sebastijan Grabar

I don't agree. People do write bad code, but just because they do, it shouldn't not be shameful. Well, maybe you are using the wrong word.

antonrich profile image
Anton • Edited on

Have you tried languages that will stop you before you do something stupid? (Rust or Elm, if you guys know others I'm interested in finding them out).

P.S. But of course they won't stop bad logic.