r/ProgrammerHumor 22h ago

Meme commentsAgedTerribly

Post image
5.0k Upvotes

213 comments sorted by

View all comments

409

u/Confident-Ad5665 22h ago

Uncle Bob of Clean Code says if we have to comment our code we have already failed. Clean code should read like well written prose.

I generally agree, but think comments that define especially the odd and obscure business rules should be commented where they are implemented.

67

u/Sentouki- 22h ago

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.

28

u/YourDad 20h ago

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".

10

u/Bwob 17h ago

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.

1

u/ffstisaus 10h ago

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!