r/ClaudeCoding • • 50m ago

Comments in codebase

Hi, I'd like to ask about your approach to allowing Claude to add comments to your code. In my codebase, information is now spread across multiple places: code comments, ADRs, lessons learned, and documentation. I'm considering asking Claude to remove comments from the code, as I believe code should be self-explanatory. However, could this negatively affect Claude's ability to properly understand the context?

1 Upvotes

12 comments sorted by

View all comments

1

u/CorpT 47m ago

lol no do not do that. Why do you care if there are comments there if they're accurate? Why make Claude work harder than it has to?

1

u/EntertainerOk4774 44m ago

As the changes produced by the Claude are in 60% in docs/comments/rest and real change affects less. I'm not sure if this not burning tokens just for sake of writing all those comments in code.

2

u/qzjul 41m ago

May burn tokens now, but saves massively on tokens when it changes something that breaks everything and you have to bug hunt

2

u/CounterAttack-Studio 24m ago

I would not optimize for tokens. Optimize for good code. You don't need comments for good code. Good code is self documenting. Sometimes it's not easy to make code self-documenting so you sprinkle comments there, but in general the world mostly switched from "copious comments" to "self-documenting code" around 20 years ago. You will of course find folks that disagree.

If you are commenting for your LLM, I suggest create a glossary or design document nearby and have instructions for the LLM to understand where to find them. I use mattpocock/skills like grill-with-docs for this kind of documentation, which helps prevent the LLM from inventing jargon and gives it a place to check against when writing code.

2

u/lgmarian 24m ago

Tokens shouldn't be the driving force for this, especially if you're not sure where your token costs lie.

1

u/CorpT 24m ago

I guess if you’re sure you’re going to get it right the first time every time and will never make a change. I’m more concerned with quality and reliability than saving a few tokens.

1

u/lgmarian 27m ago

A downside of extensive comments is that there's more that can go out of sync with the code. I recently had a jr dev put up a PR where a small method (7 lines), was less code than comment (15 line DocBlock), some of which was already wrong.

My philosophy is that comments should document intent. Let the code tell us what the code does. Where there's something non-obvious about the code, especially due to obscure optimizations, a comment should tell us what the code is doing, along with stating the intent.

1

u/ChucksnTaylor 23m ago

Get your point for sure, but that’s kinda the beauty of AI, it never writes sloppy after thought comments. A jr dev may not fully understand what they’ve written or may not bother to be precise with the comment. Those issues don’t exist with AI.

1

u/lgmarian 21m ago

Bro, it was all done by AI.