This is a huge simplification. AI is also trained on tweets, spam and explicit content, but ChatGPT isn't constantly swearing at you to send your bitcoin to a Nigerian prince.
The mistake people make here is that just because something is represented in the weights, doesn't mean it's representative of its output. And the reason for that is largely the same reason for why if I show you lots of bad code you don't become a worse coder. If anything you'll see bad code and learn to avoid writing similar code yourself.
So long as quality is being reinforced and that process is refined and improved then "model collapse theory" and arguments about how AI will write bad code because it reads bad code will continue to prove incorrect.
I do not mean to anthropomorphize their work, but I do need to improve what they produce. I think a lot of push-back to vibe-coded projects is that the person asking an AI Agent to make something do not or cannot improve what it produces, which goes back to the question asked. Is it worthwhile to learn programming now. I argue that it is.
So, it would be better if models were trained to produce provably correct code, and agent harnesses are improving to help do this, but the models themselves have been shown to be trained to provide the answer they think you want to hear, and declare a task done as fast as possible. They hallucinate (or lie) about running tests, even about writing code at all (sometimes).
How do cloud models "learn" to write better code? Where are the projects that fine-tune an open/local LLM to "learn" from its mistakes. I have yet to see any model improve on its own.
A lot of the best code I've seen is closed source, and unlikely to be represented in existing training data. A lot of the worse code I've see was online. Maybe newer coding models are getting trained better, but most I've tried are years out of date. Maybe my view is affected by trying so many LLMs. Very few have been great.
In life I learn a lot from my mistakes, not much from others' mistakes. Could we apply that to AI and code?