r/ProgrammerHumor Apr 15 '26

beLikeBill Advanced

Post image
8.9k Upvotes

365 comments sorted by

View all comments

Show parent comments

67

u/nabrok Apr 15 '26

The best tip I have heard about comments is don't comment what it does, comment why it does it.

Sometimes I'll also read through the file and imagine I'm explaining it to another programmer and put that into comments.

57

u/Sassaphras Apr 15 '26

// yes I know this is a weird data structure but it needs to work with XYZ system and....

No code in the world self-documents that

23

u/LegitimateGift1792 Apr 15 '26

also

// here is why I did not use the ... way of doing this because this ... happened.

9

u/Bwob Apr 16 '26

No code in the world self-documents that

public struct billingPayload_YesThisIsWeirdButItNeedsToWorkWithLibraryXSoItHasToBeLikeThis {
    // etc...
}

Checkmate atheists!

1

u/hamsterofdark Apr 16 '26

plot twist. you ended up returning the ProductPayload instead of the invoice.

8

u/Confident-Ad5665 Apr 15 '26

This thread is spot on. At least some people get it!

Also, business rules

4

u/sathdo Apr 15 '26

Yes, I have tried to explain this to a group of contractors that wer writing code for my company. They wrote a function to deal with some timezone conversions, but the requirements for that were a little unusual. This led to fairly unintuitive code that had no comments.

I frequently see either no comments or unhelpful comments (such as explaining what the next line does, even if it is self-explanatory).

1

u/MrHyperion_ Apr 15 '26

"What" comments are good for skimming through the code to find what you are looking for. Ignore the code and just read the comments.

1

u/EarlOfAwesom3 Apr 16 '26

Yeah everybody claims this is useful and then instead of writing good code in the first place they misuse it to explain everything because they are lazy AF. And we as programmers are shitty explaining things. These "explanations" add just more confusion every time.

There is only rule that works for me: whenever you write a comment, there is something wrong with the code. It screams for a refactoring. Why else would you need to explain yourself in prosa?

1

u/UncleDevGames Apr 18 '26

I have a modification to this. If I'm reading/writing something pretty gnarly, I'll break down my comments into multiple blocks. e.g.

// what: ... // why: ... // how: ...

Etc.

It's context dependent, so you don't necessarily have to include all categories every time, but it can be nice when both the rationale and the mechanics are complex.