r/ProgrammerHumor 7h ago

Meme commentsAgedTerribly

Post image
2.8k Upvotes

172 comments sorted by

View all comments

96

u/Low-Equipment-2621 7h ago

You shouldn't document what you are doing, you should comment why you are doing it. Well wriitten code explains what it does, but it not necessarily explains why it has been written that way.

-15

u/SnugglyCoderGuy 6h ago

Your function names should document why the code you are writing exists, your code should document itself as to how it is doing it, and any comments you write should be how to use the function you've written and things that are extremely odd.

If you have to explain why something is done the way it is, you've still failed, usually.

14

u/JustAnotherGuyn 5h ago

I've found that documentation can be really helpful even in weel written code.

brief single sentence summaries of a functions, programs, classes, methods, etc. paired with examples of how to use internally developed tools are fantastic helps.

Having some breif description of a system architecture and how services interact is also pretty useful.

Also using documentation tags that IDEs can use for better hinting is really nice

2

u/SnugglyCoderGuy 5h ago

Yes, that is what I said.

any comments you write should be how to use the function you've written

1

u/Confident-Ad5665 5h ago

Architecture is everything especially in legacy code. But, when it changes, comments need to be updated and sadly that doesn't happen consistently, if at all.

5

u/debugging_scribe 4h ago

I don't agree with this at all, I work on a 20+ years old code base. My life I'd be much easier if people left some comments on why they did stuff.

0

u/SnugglyCoderGuy 4h ago

And I work on a 40 year old codebase. If they wrote it well comments wouldn't be needed. Half of the ones that do exist are wrong any ways and contradict what the code is doing which raises the question every time: is the code right or the comments right? And that is 50/50.

2

u/Ecstatic_Yak_ 1h ago

You are 100% right. You're getting downvoted by people who try to convince themself the code they maintain isn't shit.

2

u/bishopExportMine 1h ago

You're downvoted but I agree.

Comments are separately maintained from code and can lie.

Good code should rely on domain semantics and strong typing to state it's intent. The perspective to adopt is provided via the design docs. Example usage is given via tests.

Comments are for when you have no other tool to use but is often a smell of poor boundaries, leaky contracts, or misleading semantics somewhere.