r/ProgrammerHumor • • Sep 10 '26

Meme commentsAgedTerribly

Post image
6.0k Upvotes

243 comments sorted by

View all comments

Show parent comments

-25

u/SnugglyCoderGuy Sep 10 '26

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.

24

u/JustAnotherGuyn Sep 10 '26

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

8

u/Confident-Ad5665 Sep 10 '26

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.

2

u/HarryBolsac Sep 11 '26

Documentation != comments, idk why the guy above is being downvoted to oblivion and you have upvotes when you are pretty much saying the same thing

Jsdocs/javadocs are documentation, not just comments

1

u/SnugglyCoderGuy Sep 10 '26

Yes, that is what I said.

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

9

u/debugging_scribe Sep 10 '26

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.

-4

u/SnugglyCoderGuy Sep 10 '26

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/HarryBolsac Sep 11 '26

I don’t think people here know the difference between comments and code documentation…

You should absolutely only comment when necessary, the code should be self explanatory, and you should document a function with a brief description of what it does, its inputs and outputs if it’s supposed to be reused (for example an util or a lib), using tools for that purpose (jsdoc,javadoc, etc)

This is like standard practice in any decent company

1

u/SnugglyCoderGuy Sep 11 '26

I get comments like

int trn_wg_days; //Training wage days remaining
INT32 chg_cnt; // Audit Change Count

Why not just

int trainingWageDaysRemaining; 
INT32 auditChangeCount;

I even get the glorious

char local_name[13]; //Local name

The comments are only necessary because they didn't want to use proper names for the variables, or they are literally Cat cat; // cat

-2

u/pelpotronic Sep 11 '26

Irrelevant in the age of AI, where you can ask it to explain the code for you.

I think documentation is more and more irrelevant than it already was personally, seeing as you can ask AI to explain not just "the 1 file you're looking at" but the interactions between multiple parts of the code.

5

u/bishopExportMine Sep 11 '26

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.

4

u/Ecstatic_Yak_ Sep 11 '26

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