When we go into the world of unsolved problems that someone solved and we have to maintain them, and we can't understand them immediately, we call them bad. It's my gut reaction almost every time I'm confronted with something that doesn't immediately enlighten me, even thought I know it's the wrong reaction.
We are always comparing everything to the simplest and most solved problems that were easy for us to understand. When it isn't so easy we call them "bad".
That happens in code all the time. People do things in ways that are prone to problems because either they don't have the experience to know better, or they didn't take the time to think about the domain. I would call that "bad code", no matter how pretty it looks or understandable it is.
Part of the problem is that "good" and "bad" are far too vague, so everyone will bring their own meaning. You might see people using "bad" to mean unclear, but I would count that as a sign of progress. A imagine a "bad" mechanical in this day and age engineer is someone that does stuff that costs more money, either now or later when it breaks early, but still produces mostly safe constructs because that portion of the job is highly constrained, and when they fail there, they often aren't just "bad", but may be criminally negligent if they failed to adhere to both the law and industry best practices.
If were getting to the stage that "bad" programmers are just ones that write unclear code, that's a huge step up. Unfortunately, I don't think we are there.
I don't believe in this world of unsolved problems. Most codebases reinvent the wheel like they've never seen one. Most "problems" are just a problem of picking one from known solutions and gluing it all together. People don't always pick the right solution, or they start gluing at the wrong place and won't stop once they realize it, so the end result is a mess. And then you can ask, why did they do it like this? This is not good!
If you're a programmer, you've hopefully tried to rewrite some bit of code of yours a few times until you've arrived at something that eliminates redundant logic, is more readable and less buggy than the previous versions.. don't tell me they're all just equally bad?
I have written all sorts of implementations for things that I'm positive there's a library or existing example out there that is just plain better and more thorough.
The problem is, I don't know what it is. I don't know where it is. And finding it will take time, take effort to evaluate the non-good implementations, and take effort to integrate with other systems.
Whereas I can write code now which is "good enough" (or worse, just not good at all but exists and does something right now) and then move on and hope I'll find the "better" I'm looking for later.
Experience teaches you how to adjust for the right spot on the spectrum between "build for business value" and "build for maintainability."
Isn't that funny. Get the inexperienced folk to churn out features so the experienced folk can enjoy the nightmare of perpetually repairing the monster.
But oh man, when you actually do write that one function that does the cool thing in a neat way and fits into the other crap you're wading around in without breaking anything in a way that makes intuitive sense... man, does that feel nice.
And sometimes when it comes to this I feel bad and somewhat guilty. But I can't restructure the whole trash pile and orders and budget constraints and all that, so it just has to keep growing and we shore it up where we can until it starts collapsing around the base and then maybe we can admit it was a trash pile all along and try to do better next time.
Great comment. This also happens as someone moves up in responsibility.
Also of note, I think good code is like a good plan. It's great, until it gets punched in the face. The reality is that most code is written to address constantly changing requirements with a slew of unknown unknowns. And while there certainly is a range from bad to good, what most people say is good will eventually give way to reality of constant change. The best we can do is maintain some semblance of good in this reality. I'm reminded of this excerpt from Musashi:
“What a fool I’ve been,” he exclaimed aloud. “I tried to make the water flow where I thought it should and force the dirt to stay where I thought it ought to be. But it didn’t work. How could it? Water’s water, dirt’s dirt. I can’t change their nature. What I’ve got to do is learn to be a servant to the water and a protector of the land.”
My Dad used to be an ATC and he always told me that he actually has fun doing it and loves his job. When I was little I was unable to comprehend how one can enjoy being in such a pressure situation. But now as I am older it makes more sense, as now whenever we are near a major release the pressure is still pretty high but I enjoy writing code and deliverying features too. Even if the code base is really annoying and the architecture of the platform makes me pull my hair out. It still is super satisfying to successfully do a release or when you fix that pesky bug. :)
Maintaining bad code is in a lot of ways harder than creating good code. Or at least, a person good at one of those things might not be good at the other.
I have a related theory that software development as a profession is starting to increasingly resemble being an air-traffic controller; as the actual programming parts get easier (languages, tools, and libraries get better, awful code-bases notwithstanding), the non-programming tasks tend to take up more and more time. So, you end up spending a lot more time talking to people and figuring out what to build.