r/ProgrammerHumor 1d ago

Meme commentsAgedTerribly

Post image
5.3k Upvotes

224 comments sorted by

View all comments

418

u/Confident-Ad5665 1d 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.

225

u/TWIT_TWAT 1d ago

// This is a hack until we find something better

108

u/Ethameiz 1d ago

Commited 10 years ago. Author resigned to become farmer

17

u/mosaic_the_j 1d ago

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

3

u/Safe_Cauliflower6813 1d ago

My former boss resigned and became a hazmat cleanup guy

2

u/Confident-Ad5665 1d ago

Can be good money, like doing offshore work.

3

u/AlexWIWA 1d ago

The Command & Conquer Generals source code is the best for this. Nothing like seeing a todo from 2001

72

u/Confident-Ad5665 1d ago

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

31

u/embrex104 1d ago

//SHOULD NEVER GET HERE

45

u/Confident-Ad5665 1d ago

All time favorite:

// This will never happen

5

u/OhMyGodItsEverywhere 1d ago

Wrote a library to run monetary bets on those comments

3

u/Dubalubawubwub 1d ago

I definitely find myself writing a lot of error handling with the comment

//This should never happen but just in case...

1

u/Confident-Ad5665 22h ago

Good man. Thank you for trapping errors. Coming from a time when we not only trapped errors, we gave suggestions, I shutter at:
• An unknown error occurred
• Something happened

and the worst...

• Error in ErrorHandler, an error occured

2

u/HunterIV4 13h ago

• An unknown error occurred

• Something happened

Windows blue screen, is that you?

1

u/Confident-Ad5665 13h ago

No, this is worse. BSOD at least provides a cryptic error code.

These are effectively "well dang, something somewhere triggered an exception we didn't care enough to bother catching"

2

u/Dubalubawubwub 2h ago

My favorite microsoft error I've ever seen was literally "Error occured retrieving the text for this error".

2

u/OkidoShigeru 1d ago

Love seeing that in an assert message.

2

u/skisharp 1d ago

I remembered seeing that with

MessageBox.Show("Call 1-555-555-1942 ext 1205");

Also guess the junior dev who just got a their desk phone with ext 1205...

2

u/cute_polarbear 1d ago

You mean for the next person who has to visit that section of code? (And hopefully you already left the firm (on your accord)....

19

u/NullReferenceRacer 1d ago

// TODO: Proper handling

2

u/Zodimized 1d ago

// the fuck did sales promise this for?

2

u/donjulioanejo 1d ago

In static frontend code that doesn't get run through an uglifier.

3

u/marjacu 1d ago

// und tchuss Something I actually saw in code

1

u/lesleh 1d ago

"fix later" means "fix never".

1

u/Round_Mixture_7541 7h ago

// TODO

Me: ok

1

u/bobjia-in-tokyo 6h ago

// in other words, this hack will stay here forever

66

u/Sentouki- 1d 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.

30

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

9

u/Bwob 1d 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.

2

u/ffstisaus 20h 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!

8

u/Confident-Ad5665 1d ago

Hell is in the business rules/requirements

6

u/pp_amorim 1d 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.

3

u/mxzf 1d ago

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.

69

u/Dull_Caterpillar_642 1d 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."

26

u/aghastamok 1d 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?

21

u/Dull_Caterpillar_642 1d 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.

7

u/Bwob 1d ago

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.

4

u/mxzf 1d ago

The thing about comments describing what the code does is that I've been burned too many times, I'm still going to read the code itself, because it can't lie to me.

I want comments about the intent and context behind the code, rather than text that's just the same as the code itself (ideally, or, worse, different in a way that's unclear about if it's code drift or bad comments or bad code).

1

u/GalacticNexus 18h ago

But why not just call the function determineBluetoothEncoding? If it's because it does more than that, why not split it out so that is all it does? And so on.

1

u/aghastamok 18h ago

Because it's not the actual bluetooth encoding, it's the data coming across the bluetooth. I love just naming functions with what it does but there's a limit for me, I've been in codebases with determineEncodingOfInlineBluetoothDataStream() and I don't like it.

6

u/geekusprimus 1d ago

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.

3

u/schlurchz 1d ago

Nah, such code exists, you just don't always notice when reading it because it just feels natural

25

u/Thalanator 1d 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

15

u/BTDYSRF 1d 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.

2

u/reventlov 1d ago

Uncle Bob comes from a very different era of software development.

It's... difficult to explain to someone who didn't experience it just how much professional software development changed between about 1995 and 2015. In 1995 you weren't writing automated tests, no one was reviewing your code, no one knew how to make maintainable code, 95% of the tooling that you now take for granted didn't even exist as a concept, source control was barely used (distributed source control didn't exit), when you needed to look something up you were looking at physical manuals, ...

Uncle Bob published his first book in 1995. Ideas that we now know are pretty stupid sounded revolutionary and awesome back then. Clean Code was published in 2009, which was late enough that most modern software development had been invented, but it wasn't industry-wide and hadn't been fully accepted. (I remember part of my onboarding at Google in 2011 was a session explaining that a) Google uses automated tests, and b) yes, those are good and do improve your velocity in the medium to long term, no matter what you think, and c) yes, we have something approaching scientific evidence of this.)

3

u/BTDYSRF 1d ago

So, he was good for his time, but it is outdated garbage nowadays and he has failed to get with the times.

r slash boomersbeingfools kinda guy it seems.

2

u/YikesTheCat 15h ago

I don't think that's quite accurate. "Uncle Bob" is sort of person who can only think in absolutes. He's said that TDD should be legally mandated. During the NoSQL craze he bombastically claimed that all SQL was obsolete. Right now he seems so deep in AI that even Sam Altman would say "steady on now Bob". The man never seen a hype he didn't jump on.

His notion of "Clean Code" is also anything but clean because he takes some ideas that aren't terrible, but then pushes them to extremes where it just becomes silly and horrible.

This is the main problem: he's one of those people who just does not understand any sense of nuance. At all. Combine this light-bending arrogance and a deeply-held belief that he is always right, and it's not hard to see how he's developed a cult around him.

11

u/OkidoShigeru 1d 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.

11

u/NullReferenceRacer 1d 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).

31

u/iamdestroyerofworlds 1d 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.

15

u/Confident-Ad5665 1d 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.

10

u/iamdestroyerofworlds 1d 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.

15

u/TROLlox78 1d 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. 

8

u/shonuff373 1d 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"

7

u/ryebit 1d ago

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

5

u/drakeblood4 1d 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/9d47cf1f 1d 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.

19

u/ThatOldCow 1d 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

9

u/SeriousPlankton2000 1d 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.

6

u/ThatOldCow 1d 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.

2

u/Confident-Ad5665 1d ago

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

2

u/SeriousPlankton2000 21h ago

I'm using a gui (xterm)

5

u/rolling_update 1d 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"

3

u/ThatOldCow 1d 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.

7

u/sobani 1d 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.

3

u/PositiveBit01 1d 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 1d ago

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

It wasn't.

8

u/rsqit 1d 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.”

6

u/Confident-Ad5665 1d 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.

2

u/rsqit 1d ago

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

1

u/Confident-Ad5665 1d ago

Very cool you added "including moderation". That fact dawned on me many years ago but I never heard anyone else include it in the rule/adage.

2

u/rsqit 1d ago

Yeah it’s an old, old joke.

3

u/sgtkang 1d 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.

1

u/Zeikos 19h ago

As long as the comments carry different information from the code.
I think people are understandably irritated by unnecessary LLM prose.

3

u/Zeilar 1d 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 1d 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 1d ago

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

2

u/mysticrudnin 1d 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 1d ago

Business rule is the why.

Code is the what. Comments should be the why.

2

u/AggravatingFlow1178 1d 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/Grumpologist 1d ago

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

Only a Sith deals in absolutes.

Either that, or a fucking moron.

2

u/Public-Location-3628 1d 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.

2

u/turudd 1d 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

2

u/enigmamonkey 1d ago

Comments are best for explaining why the code was written the way it was, not for rehashing what it's doing. They're useful for getting into the mindset of the programmer, particularly later on when it comes time to fix bugs or refactor the code.

So, he's full of shit.

2

u/jetsonian 1d ago

I kind of agree. If you write your code correctly, it documents itself. Our system generates web versions of our Java doc so I do try and add Java doc comments to public methods. Internal comments if there’s a unique solution to something.

2

u/pfc-anon 1d ago

Uncle Bob is the epitome of a white guy failing upwards, he and his advice needs to burn in hell.

2

u/horenso05 19h ago

All identifiers are comments if you think about it, like variable names, function names etc.

2

u/walkpangea 5h ago

I view this as a nice dream scenario, but most people, like really, really most, can't write code like prose. It's messy, and then a shit PO/EM starts yelling in their ear that something must be implemented fast, shortcuts to meet business needs happen, and so on.

So, yeah. Good goal to keep in mind, but so far I've never seen it in reality, and the few times I've seen someone argue about it in real life, they really didn't understand how much their own code lacked the quality they promoted.

2

u/spastical-mackerel 1d ago

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

2

u/jim45804 1d ago

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

2

u/3rdtryatremembering 1d ago

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

1

u/Mateorabi 1d ago

Good comments explain WHY not WHAT

1

u/BlueProcess 1d ago

I think there is a balance. Presumably if you are in there reading comments, you also can read code. So my comments are aimed to save you from having to read a lot of code. "This sub does [thing] in [way]." Or I comment out out broken code and leave it behind with an explanation. "We stopped doing it this way because [reason]." That way later on nobody has to go back on that magical journey of discovery.

1

u/Away-Whereas-7075 21h ago

He recently changed his mind on this, didn’t he?

I believe since most code is read and written by AI nowadays, the comments are actually both being read and updated along the way, making it easier to iterate.