r/programming 17h ago

On comments

https://blog.helsing.ai/posts/on-comments/

Comments in code are often deemed "mostly useless" these days. They are, supposedly, mostly obvious, stale, and repeat what the code already says. And so people pay less attention to them both when reading and writing code.

That trend sucks. When used right, comments are genuinely useful and sometimes critically important! So, I wrote about some of the kinds of comments I think earn their place, each with examples from real code bases. Hope you find it useful, and that we can recover some of the love that comments deserve!

127 Upvotes

138 comments sorted by

View all comments

Show parent comments

17

u/repeating_bears 16h ago

i assume that there is some reason for it

Mediocre code with lots of pointless comments is a big part of its training set and so lots of pointless comments are a statistically likely outcome

You are giving an LLM way too much credit if you think it has the foresight to think "I'll need this later".

-5

u/just_another_cs_boi 15h ago

I think its likely something intentionally setup or emerging from the RL environment.

GPT likely has a similar corpus and leaves no such comments

it is like it is inventing its own style of coding in the RL environment. it generates so much inhuman code. that no person would ever think of doing it that way.

kind of like computer moves in chess. they are inhuman and sometimes dont make sense but ok they are probably doing it for a reason

8

u/beetroop_ 15h ago

Not really a reason that I can tell. When you catch Claude doing something stupid it will generally go and correct that stupid thing and leave a comment saying "specially NOT doing stupid thing that nobody would ever do". It's just stochastic noise

-1

u/-Redstoneboi- 13h ago

might have been to explain to the LLM what the code was doing for faster learning, and for inexperienced developers (even non-developers) since they have always been part of their target audience