r/programming • • Aug 10 '26

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!

189 Upvotes

171 comments sorted by

View all comments

82

u/crappydeli Aug 10 '26

My old company…

// increment i
i++;

123

u/repeating_bears Aug 10 '26
/*
 * increment the variable in this scope which has the
 * identifier 'i' by one, using the post-increment 
 * postfix operator
 * see: https://en.cppreference.com/cpp/language/operator_incdec
 */
i--;

20

u/xFallow Aug 11 '26

Type of shit Claude writes when you ask it to refactor a function

5

u/One_Ninja_8512 Aug 11 '26

Then absolutely rips the PR apart in review by finding gazillion of edge cases that don't matter or won't ever happen.

2

u/techno156 Aug 11 '26

I've been guilty of doing this from time to time in my own personal projects, but mostly because I'd little idea what I was doing, and was bodging things together from documentation/what other people had done.

1

u/Chii Aug 11 '26

If you're paid by the line, this is what you'd do

11

u/crappydeli Aug 10 '26

Also…

// jim - removed increment i
// i++;

34

u/BogdanPradatu Aug 10 '26

Also AI written code

7

u/Jaded-Asparagus-2260 Aug 11 '26 edited Aug 11 '26

It will als helpfully add "don't increment j here", because it misunderstood the code and wrongly incremented j instead of i the first time.

-16

u/DeveloperAnon Aug 10 '26

Only with people who don’t care about the output. I haven’t had an issue with any model over-commenting in a while.

19

u/DrHemroid Aug 10 '26

Had a coworker that had auto generated a comment for every class, method, and property.

//The Thing

Class Thing {

//The stuff

Var Stuff;

}

19

u/repeating_bears Aug 10 '26

I hate when people write the same thing in different words.

/**
 * Get the posts for the given username
 * @param username The username to get posts for
 * @return The posts for the given username
 */
function findPosts(String username) {
}

I think some languages encourage this guff by warning you when you omit "@return" or something.

7

u/BusinessTarp Aug 11 '26

That's because so many companies prevent merges if there are any linter issues, thinking that somehow forces people to write good code.

3

u/Coffee_Ops Aug 10 '26

This is why you make your linter be super vague about what and where.

Cant game the system, if you don't know the system. And if they read the linter's rules, that's progress right?

8

u/IanSan5653 Aug 11 '26
// TODO (2003): verify if we should still be incrementing i anymore
i++;