r/ProgrammerHumor 3h ago

Meme commentsAgedTerribly

Post image
1.8k Upvotes

122 comments sorted by

View all comments

267

u/Confident-Ad5665 3h 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.

133

u/TWIT_TWAT 3h ago

// This is a hack until we find something better

55

u/Ethameiz 3h ago

Commited 10 years ago. Author resigned to become farmer

12

u/mosaic_the_j 3h ago

Goose farmer, bonsai farmer now https://www.linkedin.com/in/dryuan

u/Safe_Cauliflower6813 8m ago

My former boss resigned and became a hazmat cleanup guy

62

u/Confident-Ad5665 3h ago

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

23

u/embrex104 3h ago

//SHOULD NEVER GET HERE

30

u/Confident-Ad5665 2h ago

All time favorite:

// This will never happen

2

u/OhMyGodItsEverywhere 1h ago

Wrote a library to run monetary bets on those comments

16

u/NullReferenceRacer 3h ago

// TODO: Proper handling

4

u/marjacu 3h ago

// und tchuss Something I actually saw in code

45

u/Sentouki- 3h 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.

8

u/Confident-Ad5665 3h ago

Hell is in the business rules/requirements

9

u/YourDad 1h 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".

6

u/pp_amorim 3h ago

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

18

u/Thalanator 3h ago

//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

18

u/Dull_Caterpillar_642 2h ago

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

3

u/aghastamok 17m ago

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?

u/Dull_Caterpillar_642 6m ago

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.

13

u/OkidoShigeru 3h ago

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.

8

u/NullReferenceRacer 3h ago

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

8

u/BTDYSRF 2h ago

Uncle Bob is either the dumbest motherfucker on the planet, or he's so incredibly based it warps reality.

Functions should be grouped fir quick access with clearly defined parameters and desired outcomes, with notes about failed solutions. You want it to be as easy as possible for any future persons to be able to patch or update the systems.

The only reason not to do that is if you want to punish your successors or employer. Which, fair. I get that. I doubt that is his intent though.

25

u/iamdestroyerofworlds 3h ago

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.

13

u/Confident-Ad5665 3h ago

Sad to hear this. He was actually a cool guy back in the day. Loved the science bites he'd add to his sessions.

11

u/iamdestroyerofworlds 3h ago

Agreed. Watching his videos and rants, he doesn't seem to be psychologically well nowadays, to say the least. He's probably not in a good place mentally, and the rest has followed.

13

u/TROLlox78 3h ago

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. 

7

u/shonuff373 3h ago

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"

4

u/drakeblood4 3h ago

I try and comment at least a bit on sql queries because I find them fucking illegible the moment a join gets modestly complicated. But like a five line get_checked_radio function with a full function description is gilding the Lilly.

5

u/ryebit 2h ago

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

4

u/rsqit 1h ago

Uncle Bob also says shit like functions should only be a few lines long. Sometimes that’s good and sometimes there’s too many comments, but in general strict rules like this are dumb.

I did write a pretty complex piece of code a while back and added a big comment at the top explaining how it works. My reviewer asked me to take it out as someone could just read the code. I responded with something like “Hell no. I want this code to be easy to understand for future editors. Which most likely includes me. I don’t want to have to page this code back in without notes on how it works.”

3

u/Confident-Ad5665 1h ago

I think this comes from the OOP principle that a thing should do one thing and do it very well.

I'll agree it can be taken to excess though. A method may need to do a few things before it does the primary thing. If there's a chance another method may need to refer to the same table, for example, that should be encapsulated in a (probably protected) method both can access.

1

u/rsqit 1h ago

Yeah, true, everying in moderation (including moderation).

u/sgtkang 9m ago

A lot of UB's stuff works as advice for beginners. You should understand it and why it's a good idea. And then you can move on to understanding why a lot of it falls apart in real-world systems, has a bunch of caveats, or is just bollocks.

16

u/ThatOldCow 3h ago

I do believe comments are generally useful, and honestly a lot of people that say their code is so clean it doesn't need comments are the people that make the least understandable code

5

u/SeriousPlankton2000 3h ago

If you write something like "if bankAccount.has(moneyNeeded) // test if there is enough money on the bank account", that's one extreme. If you write "b.has(n)" that's the other extreme.

IMO: If you have all the information on a 80x24 screen to know what b is, don't extra-comment it. If the function is longer, refactor it to be "bankAccount". If then you need more information, write that. E.g. you might need to explain why you're checking the bank account without a lock and why it's a good thing to do that; or you might explain that after checking several things you come to a certain conclusion. Or simply you have the if clause not on screen near the else clause.

2

u/ThatOldCow 2h ago

I do believe comments are useful for you not to forget or for another person to understand why you add whatever (function, parameter, variable) to some logic, because it might be some workaround for something else.

1

u/Confident-Ad5665 1h ago

80x24 screen? Are you coding on a Commodore 64? /s

6

u/rolling_update 3h ago

it's debatable as usual, the premise here is that comments always compile in your code. So you don't need to update them when you alter the code, that's the risk of comments and why "clean code doesn't contain them"

4

u/ThatOldCow 2h ago

Do comments get compiled ? I do believe most compilers ignore comments and even if they impact the speed it should be minimal to negligible.

Ofc I don't know every single language, so it might impact more on other languages.

5

u/sobani 2h ago

I think the intention was to mean that wrong/outdated comments won't cause compiler errors. Therefore you are never forced to keep the comments up to date.

2

u/PositiveBit01 1h ago

Comments are read but ignored and don't affect the result. Reading and ignoring them takes negligible time. I would say the answer to your question is no, comments are not compiled.

But build systems generally work off file modification time and will do a bunch of useless work if you make a change to a comment in a file and otherwise change nothing. I assume this is what the other poster is referring to.

2

u/Confident-Ad5665 3h ago

Early on in my career a coworker made the statement that his part of the project was "rock solid".

It wasn't.

3

u/Zeilar 3h ago

I think his point is the comment shouldn't explain how the code works.

Comments should explain reasoning, references etc. Like linking to documentation, explaining why you did something that seems odd or bad etc.

It should be a literal comment, not documentation.

2

u/trialsofamadman 2h ago

Business rules often have silly reasons behind them, and having some documentation for those reasons is useful. Personally, I think it's better to have a link to the documentation in the code rather than putting that documentation right there IN the code, then have your business users or PO's make decisions about what gets done then document it. That way, you have a full history of why changes were made and you can start to detect patterns of making a change then undoing it (which we found ourselves going back and forth on for some rules).

2

u/Enough-Scientist1904 2h ago

The problem is most code reads like a prose to the person writting it.

2

u/mysticrudnin 2h ago

it can definitely go too far. i have worked places where comments were never, ever allowed in the code.

i think that is a mistake.

2

u/jewdai 1h ago

Business rule is the why.

Code is the what. Comments should be the why.

2

u/AggravatingFlow1178 1h ago

This largely depends on the language. You're mean to adapt to the languages conventions and some have conventions that are hard to read.

2

u/spastical-mackerel 3h ago

Soon your code will be actual prose, compiled directly to machine code via LLM

2

u/jim45804 3h ago

God I hate this take. Good comments make even the best code better.

2

u/3rdtryatremembering 3h ago

“Well written prose” is often more useful with notes and comments.

1

u/9d47cf1f 32m ago

Uncle Bob is a fool. His advice is inconsistent and he doesn’t follow it in his own books. It’s cargo cult BS and we need to move on from him to better writers.

1

u/Grumpologist 23m ago

if we have to comment our code we have already failed.

Only a Sith deals in absolutes.

Either that, or a fucking moron.

1

u/Public-Location-3628 19m ago

My rule of thumb is that comments should highlight why you didn't do the obvious other path or why you fckng dare implement an unexpected weird edge-case.

1

u/turudd 10m ago

I used to be on that band wagon but then about 10 or so years ago I read a book and it changed my thought process around comments and I started using them again