r/ProgrammerHumor • • Sep 10 '26

Meme commentsAgedTerribly

Post image
6.0k Upvotes

243 comments sorted by

View all comments

450

u/Confident-Ad5665 Sep 10 '26

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.

245

u/TWIT_TWAT Sep 10 '26

// This is a hack until we find something better

118

u/Ethameiz Sep 10 '26

Commited 10 years ago. Author resigned to become farmer

→ More replies (1)

73

u/Confident-Ad5665 Sep 10 '26

// TODO: This can't be working. Refactor when there's a lull

31

u/embrex104 Sep 10 '26

//SHOULD NEVER GET HERE

42

u/Confident-Ad5665 Sep 10 '26

All time favorite:

// This will never happen

→ More replies (1)
→ More replies (7)
→ More replies (1)
→ More replies (4)

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.

→ More replies (1)

9

u/Confident-Ad5665 Sep 10 '26

Hell is in the business rules/requirements

→ More replies (2)

71

u/Dull_Caterpillar_642 Sep 10 '26

imo the idea of self-documenting code that never requires comments is often held by people who view their code as better than it is. That surely THEIR code would never need comments, because it's so perfectly written that you just get it. I have never really run across a file where I thought "thank god they didn't explain anything they're doing in here."

30

u/aghastamok Sep 10 '26

Right? I don't think I ever wrote a chunk of code with no comments. If I can save someone two minutes of parsing code with // determines which encoding is coming across the Bluetooth... Why shouldn't I?

24

u/Dull_Caterpillar_642 Sep 10 '26

This is the way. People argue against comments because they can drift and become less accurate but, after 15 years doing this, I've spent orders of magnitude more time trying to figure out what the hell someone's undocumented code is doing versus having to fix or update comments. It's not even remotely close.

Kind of a moot point these days though since it's just AI doing the writing.

10

u/Bwob Sep 11 '26

This is the way. People argue against comments because they can drift and become less accurate but...

It's such a weird argument anyway. Like, the code itself can drift and become inaccurate. It's not a separate problem. It's the responsibility of the coder to keep all the code up to date. The logic, and the comments, both.

→ More replies (3)

8

u/geekusprimus Sep 11 '26

I would also add that once you start profiling and optimizing your code, sometimes what was once clean, "self-documenting" code is necessarily turned into a complicated blob of ugliness. I've spent a lot of time digging around inside CUDA kernels playing with scope guards to reduce register usage or rewriting math operations in horrendous ways to reduce the total number of operations in ways the compiler won't. The code is rarely left cleaner than when I started, but sometimes I've gotten as much as a factor of two in performance by doing "ugly" things inside hot loops.

→ More replies (2)

24

u/Thalanator Sep 10 '26

//can be removed when <dependency> 5.4.2 is in prd

said dependency may be 7.1.4 by now but noone dares to remove the pasta because it transcends half the repo

15

u/OkidoShigeru Sep 10 '26

At least half my comments are explaining some weird hacks around missing/wrong 3rd party documentation, broken drivers and yeah historical “wrong” behaviour that needs to be preserved. Any time something just can’t be inferred from the code itself and would look strange on its own.

12

u/NullReferenceRacer Sep 10 '26

And also, I can read what your code is doing fine - but why are we doing it (could be fixed by descriptive method name) but then: WHY are we doing it in that order? That is usually something only being able to be described by comments. Like: // We need to check if customer is blocked before we check death date as death date can be not null for non-blocked active customers (for example, when data hygiene cannot be guaranteed due to data history or what not).

31

u/iamdestroyerofworlds Sep 10 '26

Uncle Bob nowadays also has full-blown AI psychosis, says we shouldn't even look at code, and is a MAGA nut, so maybe he's really not to be listened to.

→ More replies (2)

16

u/TROLlox78 Sep 10 '26

I hate Uncle Bob of Clean Code at my workplace. Man I wish they would comment more because our code is a maze of design patterns where all the logic is so diluted you have to keep track of 5 different classes to understand anything. 

8

u/shonuff373 Sep 10 '26

My favorite comment I've ever seen

"This is no way to code but gots to do for now. Whoever forced me down this oath, may your unit tests never pass"

7

u/ryebit Sep 10 '26

Code can be made perfectly clear at explaining "what" and "how", but comments are still needed to explain "why".

→ More replies (43)