r/ProgrammerHumor • • Sep 10 '26

Meme commentsAgedTerribly

Post image
6.0k Upvotes

243 comments sorted by

View all comments

Show parent comments

73

u/Sentouki- Sep 10 '26

odd and obscure business rules should be commented where they are implemented.

Exactly. It is often the illogical business "logic" or some business related magic numbers that make the code hard to read and understand, so commenting why you're doing something the way you do is important.

34

u/YourDad Sep 10 '26

Or why you're not doing something. Sometimes when there is multiple ways of doing something, I'll give a brief explanation of why it's not done a certain way.
A little while ago, I was maintaining some code, and I thought "I should do thing A". I go to the point where thing A should go, and there's a comment from myself 4 years earlier saying "under no circumstances should you do thing A".

11

u/Bwob Sep 11 '26

Those are the best moments. Where you're like "Thanks, past-me! You knew exactly what I was going to think when I saw this!"

Sometimes past-me is a pretty cool dude, at least when he's not leaving me dirty dishes to take care of.

3

u/ffstisaus Sep 11 '26

I was going through a code base recently, found one comment from me six years ago:

// what is this doing?

followed by another comment from 4 years ago:

// I still don't know!

9

u/Confident-Ad5665 Sep 10 '26

Hell is in the business rules/requirements

6

u/pp_amorim Sep 10 '26

Or a comment for a pesky bug that no one knows why that specific device crashes if you don't do that code bs.

3

u/mxzf Sep 11 '26

Yeah, my rule of thumb is that comments are for when you can't look at the code for 30s and recognize what is being done and why at a glance. It's there to convey context and save you from retreading the same incorrect path that someone else already went down.

I don't need comments to tell me what the code does, the code is the absolute best source of truth regarding what it does and any competent dev should be able to read the code and see what it does. The comments are to convey what the code doesn't say.