Now listen here you little shit
ITT: AI induced dunning-kruger. Everybody can write maintenable code, just somehow it happens that nobody does.
Most of the unmaintainable code I’ve seen is because businesses don’t appreciate the need to occasionally refactor/rewrite or do anything to maintain code. They only appreciate piling more on. They’d do away with bug fixing too if they could.

Many opensource projects are in same state, I know for sure my projects become spaghetti if I work more than a year on them.

Besides, I’d argue that if you need to rewrite (part of) it is because it wasn’t maintainable in the first place.

I disagree. Rewriting is a core component of maintaining a code base. It’s the evolution of code. Not rewriting and hooking in some janky way is much worse. No one can see all the possible needs of code the first time they write it. Or even the tenth. Updating the code by rewriting sections is the healthier way to use everything you learned since the first time you wrote it to keep it clean and improve it.

Exactly. Elegant code requires domain expertise, which no one has on during the first attempt.

Strident attempts at elegance during the first domain-expertise-free try tend to just result in different kinds of shitty code.

Of course, experienced programmer obviously achieve lower shittiness, from day one.

But truly elegant code requires exploring the domain, and learning what works there.

Shitty barely good enough code walks so that elegant code can someday replace it.