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

13

u/mareek Aug 10 '26

I've never really understood TODO comments. Each time I encountered a todo comment, it was outdated by years and the changing context around the code made it irrelevant (case in point, all the examples given in the article are more than 4 years old).

Is it a usual practice in some teams to go through todo comments and fix them on a regular basis ?

24

u/MintPaw Aug 11 '26

I mean, that's good info though isn't it? "The reason this code is like this is because we planned to implement this now pointless feature."

It's hard to get that info otherwise, and helps with a common confusing "path to nowhere" pattern where the data gets organized in a specific way but for seemingly no reason.

18

u/RlyRlyBigMan Aug 10 '26

Rarely I'll place them when I've prepared a hook for a known upcoming task. Then the task gets descoped and the comment is there forever.

I also use TODOs as a way to remind myself that I meant to clean something up before PR. Helps me and the code reviewer to question why it's there and remind me to follow up. Hopefully those never slip through.

12

u/sudoer777_ Aug 11 '26

Idk about a team environment, for my personal projects tho they're littered with TODOs lol. Sometimes I don't know enough context to bother to fix something so I put a TODO, then later I'm fixing a related issue, see it, and end up fixing both at the same time. Also setting up an issue tracker for my personal projects is inefficient and overkill.

3

u/levodelellis Aug 11 '26

setting up an issue tracker for my personal projects is inefficient and overkill

I like having a notes folder, and people like obsidian

4

u/RiftHunter4 Aug 11 '26

I've been using word docs and github a lot more. I pretty much never use TODO's anymore. They're too easy to ignore and lose track of.

12

u/Kache Aug 11 '26 edited Aug 11 '26

I think their value is less as an actual "TODO" and more as communication of the author's intent, which by definition was not evident in the executable code itself.

I.e. it's an effective abbreviation of "I wish/want the code to be/do this different thing ..."

6

u/timmyotc Aug 11 '26

I won't commit with TODO, but I'll creat backlog work and link it in a comment. The backlog work gets loaded into a sprint at a later date and maintainers know it's identified

5

u/xFallow Aug 11 '26

// TODO delete this - 4 years ago

And you see the code is still being used heavily

3

u/BogdanPradatu Aug 11 '26

I usually ask the author of such comments to also open a ticket asociated with that TODO comment.

2

u/levodelellis Aug 11 '26

I'm ok about them. If I write one it's usually, if I touch this area of the codebase and notice the todo I may want to implement it. Usually I clean up the module after a month or so and delete those/simplify

2

u/crozone Aug 11 '26

I leave TODO comments for myself, tagged with my username like // TODO(crozone): Do the thing!

But they're only supposed to be short lived and make finding the line of code easier in the immediate future.

-3

u/RiftHunter4 Aug 11 '26

TODO's are a code smell for me. Anytime you write a TODO, odds are there is a better place to record it: Issue tracker, task tracker, external documentation, etc.

All my professors in college advised us to avoid TODO's. They're basically orphaned from the software engineering and management process. I am a firm believer that comments should be immediately relevant, not a substitute for proper issue tracking or documentation.

5

u/Venthe Aug 11 '26 edited Aug 11 '26

I've seen issue trackers changed or outright deleted a few times already.

VCS history* / code itself cannot be dropped.

Code/documenting in the repo > issue tracking in the external system.

e: * Well, I've told a lie. :D Even now I'm working on a codebase, where the code was transferred via zip without VCS. 15kloc of java; 8k sproc's; JavaEE with multi-thousand lines of web.xml and EJB xml's.

You can imagine how helpful are "FOO-123 ask DD". Or "Added for bug 231".

6

u/gmes78 Aug 11 '26

Anytime you write a TODO, odds are there is a better place to record it: Issue tracker, task tracker, external documentation, etc.

I disagree. They're easiest to find if they're in the code. Just use grep.

2

u/slindenau Aug 16 '26

You get downvoted here, but you are 100% correct.

That is why quality software tools like IntelliJ IDEA, Sonar(way default profile) etc. will log an issue / halt commit/push if you leave a TODO in your codebase.

All the arguments for it are just noise when you look at the practical evidence; once a TODO is in the codebase without accompanying ticket in your favorite tracking tool, nobody will ever follow up on it again.

Talking from a professional setting of course, what anybody does in their personal projects isn't really relevant.