Copy-Paste
In the beginning there were only books and magazines. Their code could of course be retyped, but it didn't lead to disasters.
Then Google appeared (as the first convenient search engine), and developers started googling a lot. Unclear code snippets started appearing in projects. "This thing does such-and-such, don't touch inside" became the norm. But those snippets patched holes where competence was lacking.
Then StackOverflow appeared, and code often became a collection of such copied pieces that developers only stitched together crookedly.
Finally, the peak of copy-paste came with large language models (ChatGPT and the like), which can stitch different code fragments together better than mindless copying.
Symptoms
- The project contains fragments "from somewhere on the internet" that nobody fully understands.
- Small copies of the same code scattered in different places.
- "Don't touch inside — it works" as a principle.
- AI-generated code without tests and without understanding edge cases.
Why it happens
The result is either a great time-saver if you understand every line of code, or the most awful junk code that will cause a lot of trouble for everyone else over time.
AI assistants add a new dimension: they produce code fast and confidently, so the temptation to accept it without scrutiny is even higher. The errors of language models are insidious precisely because of their plausibility.
Example
The "bad" version: a copied snippet without understanding and with untested edge behaviour:
# taken from StackOverflow, don't touch
def parse_dates(s):
import re
return [d for d in re.split(r'\s+', s) if d]
The "good" version: explicit understanding and a test for edge cases:
def split_tokens(s: str) -> list[str]:
"""Split the string into tokens by whitespace, skipping empty ones."""
return s.split()
def test_split_tokens():
assert split_tokens("a b") == ["a", "b"]
assert split_tokens("") == []
How to fix it
- Don't insert code you don't understand line by line.
- Collapse duplicates into libraries and functions.
- Code from the internet and from AI — run it through code review and tests.
- Explain "magic" fragments with comments until you've figured them out.