I mean, I write pseudocode in comments before writing the actual code all the time. It's a great trick for organizing and structuring what you're about to write. But then I delete the pseudocode comments.
For real - comments were never golden, because they easily slip through updates and drift apart from the code they decorate. With AI, that might be happening from minute 0 lol
I'm using a static analysis rule that tokenizes comments and compares to the code, and reports an error if the overlap is too big. highly satisfying to remove such comments
Heh that reminds me of a project a couple years ago had to combine data into a CSV type file. But the data could include “,|” and all the other regular delimiters. We decided to make 🚀 we called it RSV for rocket separated values
I remember when I was using cursor I had this maddening problem where it would always want to delete all my human written comments. Honestly that was even more annoying
I think its been like nearly a year since gpt was doing emojis. I think they're fucking great and should be included. If your Rstudio is sitting in the second monitor you can tell how far along it is at a glance because you just saw rockets or a dolphin or something. But people had to be such dour pricks about the emojis because the bots were using them.
Always made the day just a little brighter seeing that somebody else suffered through that spaghetti marsh before you. Like when games show you gravestones of other players.
/**
* load bearing indicator of critical success
* along the mainline seam. Upon resolution
* of the primary action, if zero or fewer
* errors are thrown, carries a text entry to
* the developer tools, enabling visual
* confirmation of task completion
**/
console.log(“it worked”);
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.
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".
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.
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."
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?
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.
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.
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).
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.
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.
Ideal self-documenting code should have comments. The code communicates as much as can be made apparent without commenting, and then the comments pick up the slack. Proper variable and function names can explain individual steps or provide useful context, but standard comments should still be used if they can't explain the "why", or if not everything can be explained by entity names.
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.
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).
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.
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.
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.
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
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.
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.
// Overdrafts are not permissable at this time, and we do not support credit.
// Account must have sufficient money before purchase.
if (bankAccount.has(moneyNeeded))
Or maybe...
// Purchase doesn't care if account has money or allows credit.
// TODO: Rename function to "canSupply" on slow day.
if (bankAccount.has(moneyNeeded))
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"
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.
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.
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.
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.
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.”
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.
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.
"Uncle Bob, please write a 256-branch jump table in five lines. We need to accomodate a hardware interrupt that can flag 256 distinct states, with minimal performance costs."
Now that you mention it, I'm curious how he'd respond to something like that.
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).
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
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.
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.
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.
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
// This logic is perfectly self-explanatory and needs no explanation.
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y;
i = 0x5f3759df - ( i >> 1 );
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) );
// y = y * ( threehalfs - ( x2 * y * y ) );
return y;
}
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.
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.
Hmm... useful if your for is unreasonably long, and can't fit on a single screen. That's a pretty big if, though!
I like this, myself:
namespace A {
namespace B {
} // namespace B
namespace C {
} // namespace A::C
} // namespace A
Helps if the namespaces are long, which is definitely possible if they contain bulky classes or the like. Not sure which of the two I like better; B's start matches its end (making it trivial to jump between the two without collapsing the block), but C also makes it clear which scope you're re-entering.
Lots of people in the comments seem to think you can name a function or variable so well it'll remind you about that edge case in the vendor api where floats with more than 2 decimal places in the json will cause a crash.
That's a fabricated bug to protect the innocent but that's how I feel about some of these comments.
I guess comments are out but functionWithSuperLongNameToClearlyCiteAllEdgeCasesAndWorkarounds is all good.
As an old, traditional programmer the highest compliment I've had was from a guy who was maintaining a custom accounting system I wrote at the U. "6500 lines of code, plus comments. It took me less than an hour to make a major change."
Verbose comments are not necessarily targeted at humans, they provide context so that consequent AI changes are more accurate.
Im still unsure how I feel about the paradigm shift in development, but that's where we are heading. Eventually everyone stopped writing ASM because C language was higher level and more efficient. It seems we are heading towards natural language becoming the programming language norm
But comments aren't always accurate. Code can change without the comments changing (or they can be just wrong). If the comments are verbose nightmares, that's even more likely. In my experience, Claude will often mess around with code and forget to update comments it made earlier. Not to mention the context in these comments is often not even very helpful. It's often filled with irrelevant details that aren't really important to anyone reading it. My experience has also been Claude will trust comments over the code itself, leading to completely incorrect assumptions. It will only get worse the more bad comments get left. This line of reasoning helps no one, not even the AI, and is just an excuse for lazy development practices.
It's not really an excuse for lazy dev practices when you're enforcing an agent to constantly relearn context for a repo. There's constitutions and memories and scripts to run, but in my experience claude often modifies comments as it changes code.
This isn't me saying "leave all comments" No. Most comments are garbage trash, but you have to figure out which ones are relevant for new context on an old file.
They seem to comment for dumber models, though, which makes them overly verbose for their own family of models.
I prefer to tell agents to keep comments concise, to serve as JSDoc, and instead have more detail in planning documentation and to instruct it to have the code match the documentation.
It is even worse, because the EU requires everything Claude and GPT generate to have watermarks. And they best work in Code via comments, because there are not many possibilities to generate fingerprints for for loops compared to comments.
Hideous. At least that's a test where it's prone to happen a bit more. Did you end up seeing lots of that crap in methods/classes that you were intentionally invoking as an API in regular code?
I write tests with names sort of like that since you need a unique name with some way to describe it and don't really care about calling it explicitly (since it'll be run automatically). Everywhere else though, the names matter a lot, particularly since it's important for consistency and for refactoring later on.
I got accused of submitting AI code to an open source repo because I commented my code well, it was clean, and the changes to the PR reflected exactly what the critiques were.
yeah, that's the op image aspect of ai histeria - coders whose ego is hurt because machine did something better than them will throw out your manual code now out of the window if it's clean and wellcommented (and comments are helpful for other coders in cooperative work right?)
So I love AI. But this is one place that needs improvement. So often the ai code, which learned this from humans, says what the line does without providing any important context or reasoning.
If it spelled out the “why” or the “how” or anything other than the “what” then they would be useful.
This has notably improved in recent models, but the verbosity of comments is still too high.
Open AI recently posted a prompt for Astra which addresses this for creative writing purposes, but not only is it great for other models, is great for code comments too!
What type of code/app are you releasing? This is pretty standard stuff for webdev, but it's not usually done by AI (which would be overkill). Most of the time, at least compiling output for the web, it goes through a minifier/uglifier that not only strips comments but also renames everything and removes whitespace and etc, so comments are only part of it.
returns true if x; otherwise false If you can't infer that it returns false if not x then I don't want you to touch the codebase. If it does not otherwise return false then I don't want me to touch the codebase
problem not on code comment itself but rooted in the problematic LLM assisted, never curated tone. Suggest improve by rewriting. Would you want to rewrite the comments, referencing the newest code logic?
There was no commented code prior to 2022. Comments were frowned upon because they added too much verbosity, were never maintained and were existing to just state the obvious.
Now AI is adding comments everywhere but at least they explain the situation as it should, and you can always tell it to skip it.
vibecoded comments arent even well commented, theyre way too wordy, take forever to get to the point, and make the code practically unreadable. You spend more time scrolling past comments to get to the actual logic than reading the code itself.
they do whatever you tell them to do. If you want them to write comments, they will. „I didn‘t tell it what it should do and it failed to guess my thoughts“
Has anyone here actually tried to make AI work? It feels half the sub formed their opinion about AI in 2023 with free ChatGPT that forgot their question once and hasn’t touched it since.
Well yeah, you can obviously tell the AI to write anything from zero comment to literally commenting every line. But I don't think that's the point, it's about the default out of the box experience.
If you regularly need comments your code isn't nearly as straightforward as it should be. Comments are reserved for things that are not obvious or that break conventional wisdom and best practices.
Comments come with a cost so only use them where they are actually needed.
Idk why you’re being downvoted, you’re pretty much quoting uncle bob, comments should only be used when necessary, it should not be standard practice, unless we are talking about javadocs/jsdocs or something like that
992
u/CannibalPride Sep 10 '26
Emojis on code…
398
u/n4ke Sep 10 '26
We all miss the good old // here be dragons, do not touch!
33
u/hyrumwhite Sep 11 '26
32
u/remy_porter Sep 11 '26
AI tools write TERRIBLE comments. They over explain the code, contain context that belongs in the chat.
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.
42
u/Bomaruto Sep 10 '26
Unnecessary comments has always been frown upon.
37
u/bbpsword Sep 10 '26
Stunning amount of "comments are bad" people who have clearly never worked in complex legacy scientific systems lmao
24
u/dvdmaven Sep 10 '26
As an old, traditional programmer the highest compliment I've had was from a guy who was maintaining a custom accounting system I wrote at the U. "6500 lines of code, plus comments. It took me less than an hour to make a major change."
6
u/Myaltforsomeshit1234 Sep 11 '26
Yep AI broke commenting and emojis basically
6
u/VG_Crimson Sep 11 '26
I would argue AI comments are not well.
If over 30% of the lines in a file are just comments, it's only creating more chaos.
I would however leave them, as those comments are the only clue as to how the AI broke the code when it inevitable breaks.
39
u/Raywell Sep 10 '26
Verbose comments are not necessarily targeted at humans, they provide context so that consequent AI changes are more accurate.
Im still unsure how I feel about the paradigm shift in development, but that's where we are heading. Eventually everyone stopped writing ASM because C language was higher level and more efficient. It seems we are heading towards natural language becoming the programming language norm
11
u/Beginning-Ice-9008 Sep 10 '26
It is even worse, because the EU requires everything Claude and GPT generate to have watermarks. And they best work in Code via comments, because there are not many possibilities to generate fingerprints for for loops compared to comments.
9
u/pe1uca Sep 10 '26
At least is still a comment and not self-documented code...
2
u/ekun Sep 11 '26
The repo with the well-constructed clanker instructions is what I am really looking at this point.
But maybe that is a dated way of thinking from the 2nd quarter of the 2020s.
2
u/Bardez Sep 11 '26
I got accused of submitting AI code to an open source repo because I commented my code well, it was clean, and the changes to the PR reflected exactly what the critiques were.
🤷♂️
3
u/chisleu Sep 11 '26
So I love AI. But this is one place that needs improvement. So often the ai code, which learned this from humans, says what the line does without providing any important context or reasoning.
If it spelled out the “why” or the “how” or anything other than the “what” then they would be useful.
This has notably improved in recent models, but the verbosity of comments is still too high.
Open AI recently posted a prompt for Astra which addresses this for creative writing purposes, but not only is it great for other models, is great for code comments too!
Try it out if you can find it. I’m mobile now.
3
u/tony3841 Sep 10 '26
Would you rather have LLM generated code without comments?
2
u/pbjtech Sep 10 '26
took out all comments on public releases, but still have them in dev production and use ai to strip them out for release
2
u/boobiebamboozler Sep 10 '26
We’re largely writing code for gen ai to read now, so more verbose comments seem to be helpful to give it context
1
u/ApocalyptoSoldier2 Sep 11 '26
returns true if x; otherwise falseIf you can't infer that it returns false if not x then I don't want you to touch the codebase. If it does not otherwise return false then I don't want me to touch the codebase
1
u/Round_Mixture_7541 Sep 11 '26
Who tf comments their code?
1
u/Fadamaka Sep 11 '26
I wouldn't call AI comments well commented.
1
u/Bary_McCockener Sep 12 '26
Giant ASCII comments so I can find my way in the VS code miniature window on my giant run-on scripts
1
u/Unlucky_Age4121 Sep 12 '26
problem not on code comment itself but rooted in the problematic LLM assisted, never curated tone.
Suggest improve by rewriting.
Would you want to rewrite the comments, referencing the newest code logic?
1
u/FrenchieM Sep 12 '26
There was no commented code prior to 2022. Comments were frowned upon because they added too much verbosity, were never maintained and were existing to just state the obvious.
Now AI is adding comments everywhere but at least they explain the situation as it should, and you can always tell it to skip it.
1
u/New_Salamander_4592 Sep 24 '26
vibecoded comments arent even well commented, theyre way too wordy, take forever to get to the point, and make the code practically unreadable. You spend more time scrolling past comments to get to the actual logic than reading the code itself.
1
u/mischanif Sep 10 '26
What you gonna do when AI comes for you
1
u/DoctorWaluigiTime Sep 11 '26
If the comments are making you make that face it's not "well-commented."
1
u/Lhaer Sep 11 '26
Comments are still useful :D
1
u/GoddammitDontShootMe Sep 11 '26
Since when do LLMs generate good comments?
-10
u/seba07 Sep 10 '26
That's already outdated from my experience. Agents don't comment code. That's something only ChatGPT did.
242
u/[deleted] Sep 10 '26
[removed] — view removed comment
2
u/[deleted] Sep 11 '26
[removed] — view removed comment