Claude's code comments – too much or just enough?
Posted by lalaleslieeeee 10 hours ago
Has anyone else noticed that Claude leaves a lot of large code comments sprinkled throughout its work?
Some of my meat-based engineers have taken issue with it and directed Claude to never leave comments unless strictly necessary, but I want to know what others think. Personally, I write and read a lot of code comments so I’m confused about why these specific comments are so offensive to my fellow engineers.
I have two questions: 1. Why does it do this? 2. Do you have feelings about it?
Is the agent leaving breadcrumbs for other agents? Do they improve the output of future agent-driven code or is it just a stylistic choice?
I don’t want to devolve into a discussion about the purpose of code comments at-large. Instead I’m wondering if there’s a purpose behind the specific comments that agents leave
Comments
Comment by carlostkd 9 hours ago
This is basic from school.
Why not?
Two reasons: First, you are telling an attacker, "Look, my code works like that, and this function does that, etc., etc." Without comments, let the attacker read and try to understand everything alone, if he can.
Secondly, it's easy to copy totally or partially, you spent hours coding and anyone can say "Oh look a nice function; it's what I was looking for."
The normal behavior should be keep comments for yourself in a development code copy delete all comments for production.
Comment by sollawen 9 hours ago
Comment by gojkoa 6 hours ago
I treat comments inside code as smells. They exist sometimes because the author wanted to say something else but was prevented from doing it because of existing conventions, sometimes because a piece of code is difficult to understand, sometimes because a large piece of code has multiple responsibilities. For things like that, I tend to clean up the code to make the design more intention revealing and break large pieces of code into smaller pieces with appropriate names. I tend to document behaviour using unit tests (where the unit test has the name that would be in the comment). This was a rule before claude code, and it still is for us.
In general, this leads to better code, that's easier to understand, manage and maintain. It also leads to functional decomposition that's easier to test than a large blob, so fewer bugs.
We have linting rules preventing claude from leaving comments inside code, and forcing it to apply these refactorings. The one to write tests to document behaviour instead of just commenting it is especially useful as there's proof that the code is actually doing what the comment suggested, and ongoing checks that it still does that. a comment may become stale easily without you noticing.
as for the reason why claude is doing it, my best guess is training material included lots of comments.
Comment by ctkqiang96 6 hours ago
Comment by ventana 9 hours ago
Comment by DrOctagon 5 hours ago
Comment by specia1ne 4 hours ago
Comment by sshworld 9 hours ago