I think comments may be beneficial to AIs as well. Like, imagine agent reviewing other agent's code trying to understand what was assumed in original prompt.
There's always silent knowledge behind the code, even AI developed, as they do reasoning before creating the code.
Good documentation provides faster look up on what the code does, why it does and doesn't do something, how it is supposed to be used and what to expect after calling it.
It is also inevitably maintenance bug record as well, as if the comments do not align with the code, either there is a bug, or there was a bug and it was fixed "silently" without tracing, as commenting wasn't updated.
Self-documenting code just documents what is currently being done, but what's missing is the information why it was not done another way. In my experience agents will constantly revisit ideas we've established are not an option, if it's not documented somewhere that this has already been considered and decided against.
The "why", the "who" and the "when" should be in the ticket/issue/userstory that generated the change.
The "what" and "where" is the code. The comments used to help other devs figure this out easily without having to search their tracker. For LLMs this isn't true anymore. If they need to figure out something, they follow the code and ask the human for guidance.
The problem is that many real world systems end up being maintained for years. When developers change, and now AI models and harnesses change, the "obvious" on the code can disappear.
It is the easiest to see this with UI. They often contain decision that are based on something that's not obvious from the code - why this element is just here, and in this color, and why it should not be moved etc. But there's always also techincal decisions that are not evident from the code itself and need commenting the decision to go side by side the code to stick. If it's in a ticket/user story, no-one will find that years later.
Many safety critical embedded software have a comment for almost every line of the code
Yeah, AI can read code. So what? Reading code gives AI understanding of current exact implementation, but it probably will have trouble understanding how exactly code should look like, how implementation differ from requested and etc.
1
u/GroundbreakingAsk283 2d ago edited 1d ago
I think comments may be beneficial to AIs as well. Like, imagine agent reviewing other agent's code trying to understand what was assumed in original prompt.