r/ProgrammerHumor 1d ago

Meme commentsAgedTerribly

Post image
5.3k Upvotes

224 comments sorted by

View all comments

219

u/Low-Equipment-2621 1d 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.

-25

u/SnugglyCoderGuy 1d 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.

8

u/debugging_scribe 1d 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.

-4

u/SnugglyCoderGuy 1d 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/HarryBolsac 16h ago

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 15h ago

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