
Why we should document AI-generated code like real developers do
I've been thinking about something.
We've gotten really good at using AI to generate working code, but we're not treating it like production code in terms of documentation.
Traditional developers spend significant time documenting their code because they know future them (or their teammates) will need to understand, modify, or debug it later. But with AI-generated code, we often just copy-paste and move on.
The problem:
You generate a perfect solution today.
Three weeks later, you need something similar.
You can't remember what the original code does or why you built it that way.
You end up re-prompting for the same solution.
What I've learned:
Taking time to document AI-generated code (what it does, why you needed it, how to modify it) creates a knowledge base you can actually build on. Instead of starting from scratch each time, you're accumulating reusable, understandable solutions.
Anyone else notice this pattern? How do you handle keeping context around the code AI writes for you?
Replies
@busmark_w_nika made my point.
Many who use AI for coding lack formal programming skills and skip documentation, which can backfire as AI sometimes changes code unpredictably (I've survived this tide somehow).
minimalist phone: creating folders
To be honest, most people using AI for code generation often do not have coding knowledge and probably do not think about creating documentation. The other thing: it must be confusing to create some documentation when AI changes the whole code even though you prompted not to change anything :D
I think adding proper comments and docstrings (or even asking AI to generate them) is usually enough to make AI-written code understandable and easier to debug later, at least thats what I do. And since you can always feed the file or even the whole codebase back into an AI or agent to get summaries or run specific tasks, managing context becomes a lot easier.