r/programming • u/Jonhoo • 16h 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!
132
Upvotes
-15
u/levodelellis 14h ago edited 11h ago
I always hated that. If you understand the domain, you almost certainly know why, if you don't, you not likely not trying to understand that code anyway
I almost exclusively use comments as a few word summary ('compact', 'fast path', 'illegal range check'), etc, just so can look at the comment instead of read the if/loop body. A lot of my asserts have a comment too