r/ClaudeCoding • • 25m 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

8 comments sorted by

1

u/CorpT 22m 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 20m 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.

1

u/qzjul 17m ago

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

1

u/CorpT 0m 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 2m 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/gouldopfl 4m ago

I can tell you from 4 decades of experience. Leave them there and enhance them even more. I can remember on several occasions going back into 10 year old code, in a language I hadn't used for years, my skill level was not as good and wondered what the hell was that.

0

u/cleverhoods 18m ago

Do not allow Claude to write comment like that in code. A 1-2 line of code documentation is fine as long as it’s about the code and code only.

All the rest goes in your progressive disclosure (whatever that might be, memory, custom loading logic, rules, claudemd or agentsmd files)

0

u/CounterAttack-Studio 9m ago

This instruction works pretty well for me:

Don't write comments; make the code clear enough not to need them. The one exception is a line whose purpose the code can't convey.

If the context gets too polluted Claude will miss it sometimes but in general it always follows it.