defaddOne(number):# This function takes a number as input.
# It then adds exactly one (1) to that number.
# Finally, it returns the resulting number.
# Example: addOne(5) returns 6, because 5 + 1 = 6.
returnnumber+1defprocessData(data):return[(lambdax:(lambdaf:f(f,x))(lambdaf,n:1ifn<2elsen*f(f,n-1)))(abs(v))^(i<<2)fori,vinenumerate(data)if(v&(v-1))!=0][::-1]defreturnNumber(number):# This function returns the number passed to it.
# The number is not modified in any way.
# No mathematical operations are performed.
# The returned value is identical to the input value.
# Example: returnNumber(5) returns 5.
# WARNING: Passing a different number will return a different number.
returnnumber
No one know what processData does, why it does it, or where the algorithm came from. That entire data flow is written in stone, blessed by the divine, and immortal, because no one is or will ever be alive who can uncover the secrets of why it was written.
The last two people who attempted to change this blessed, heavenly body of code crashed a dozen production systems and were summarily sacked.
The rest of us will just carry on, praying we aren't cursed to deal with an outage related to the divine code artifact.
See that red sign right there? The one with eight sides and the big white letters that say STOP? That’s a stop sign. When you see that sign while driving, it means you have to bring your car to a complete stop. Not just slow down. Stop completely. Now, look at the road in front of you. Before you go any farther, you need to look to your left, then to your right, and check for cars, cyclists, or people crossing. See, the stop sign is there to make sure you don't drive into danger or get in someone else's way. Once you've stopped, checked everything, and made sure it's safe, you can keep going. So remember, whenever you see that red sign right there, it's telling you one simple thing: 'Stop. Look around. Make sure it's safe. Then go'
Then a Markdown file informing about various places you see a stop sign and how it differs from other signs.
It will also add a history lesson about who invented the stop sign and why, what was used before it was widely spread, and past accidents that happend because there wasn't a stop sign.
AI generated code in any decent model is written for the benefit of AI, and shouldn't have half this bullshit.
Sincerely, your local Clean Code nerd who has to begrudgingly accept that good code now has fucking banal comments even when it's painfully obvious what the code does
Remember, your code should be clear enough that people can understand "what" the code does, comments should explain "why?" or "how?". Never answer "what?".
Certainly all things equal this is often true, provided it's not something complicated. But I often wind up doing pretty math heavy, lengthy functions. At some point you run out of descriptive helper or intermediate variable names. If I don't comment heavily, I forget what any of it was the next day even, let alone a month from now or for someone else entirely. Making sure your comments don't get stale also is a habit that can be built!
So those would be comments that answer "how?". When I refer to "what" comments I'm referring to comments which say what the code already says it's doing. So, as an egregious example `a + 1 // add 1 to a`
While math heavy code might have formulas with names, maybe some Lean, maybe some links. Giving a high level overview of how it's achieving the requirements it is fulfilling.
The why is obvious in the stop sign context because there's rules of the road, yes, but in general explaining that another process has priority is probably useful if there is no general "rules of the road" in your codebase.
People complain about comments because of comments like this:
// Returns the size
int getSize();
The size in what? Elements? Lines? Bytes? KiB?
The other problem is with "elapsed time": is it seconds, milliseconds, microseconds or nanoseconds, and what's the reference point? Epoch from 1970, or the start of the program, or what?
where are you seeing references to "elapsed time" outside of the context of a particular start timestamp such that it would be unclear what the reference point is?
obviously this issue is quite easy to stumble across with just "time" but i've never seen "elapsed time" not be paired with some particular timestamp to compare against
I legit do dumb stuff like this in my comments, and make comments about how the programmer who wrote it should be fired. I hope someone reads it some day and thinks "what the hell is wrong with this guy"?
I had one class in college where we had to write comments like these or have points off. Most of the assignments were very short and very simple and didn't actually require comments, but comments were a part of the grade, so we had to do this kinda thing.
Yeah, I had a class like that and discovered JAutodoc to solve that problem. One hotkey and everything gets comments.
It created the most banal stupid comments, like "Gets the X" on a function named getX, but it checked the checkbox that the grading software used, so it did the job.
On the flip side, that whole experience created a life-long hatred for nonsensical comments in code that take longer to read and understand than the code itself.
yup, meanwhile there is no explanation for the light above the sign and if this was my really old code the light would just be there because i cant figure out how to get the sign to work without it... perhaps because its inside the light markup which is also why i needed the comment...
No sign without a story. From personal experience people probably keep ignoring that sign. We have about three signs in our bathroom informing you about the existence of a toilet brush and begging people to use it, but still, somehow, that doesn't seem to be enough. Sometimes you just don't know how to get any more clear
Lol, that is where AI comes in, i ain't wasting a minute trying to understand that on my own, i will copy paste it to chatgpt or Claude and let them do it.
Why do I need to comment it if it worked when I wrote it? If it breaks I’ll start over and write it again. Real talk most of what I’ve actually done in programming is writing regexes and I can say if you’re actively working on a dataset with specific patterns, you do just get to a level where you can read off regexes and know what they’re for. Of course when you stop work on the project for a month or so and come back you’ll still be staring at a mess.
117
u/Western-Anteater-492 1d ago
133
u/YnkDK 1d ago •
Not with AI. It would be
See that red sign right there? The one with eight sides and the big white letters that say STOP? That’s a stop sign. When you see that sign while driving, it means you have to bring your car to a complete stop. Not just slow down. Stop completely. Now, look at the road in front of you. Before you go any farther, you need to look to your left, then to your right, and check for cars, cyclists, or people crossing. See, the stop sign is there to make sure you don't drive into danger or get in someone else's way. Once you've stopped, checked everything, and made sure it's safe, you can keep going. So remember, whenever you see that red sign right there, it's telling you one simple thing: 'Stop. Look around. Make sure it's safe. Then go'
Then a Markdown file informing about various places you see a stop sign and how it differs from other signs.
11
u/saig22 20h ago
A good comment would explain why a stop sign is needed here.
29
u/zeddash 1d ago
Remember, your code should be clear enough that people can understand "what" the code does, comments should explain "why?" or "how?". Never answer "what?".
7
u/MaskedBandit77 1d ago
Please stop bullying me.
7
u/bluefishcrab 1d ago
People complain about comments because of comments like this:
The size in what? Elements? Lines? Bytes? KiB?
The other problem is with "elapsed time": is it seconds, milliseconds, microseconds or nanoseconds, and what's the reference point? Epoch from 1970, or the start of the program, or what?
13
u/BedSpreadMD 1d ago
I legit do dumb stuff like this in my comments, and make comments about how the programmer who wrote it should be fired. I hope someone reads it some day and thinks "what the hell is wrong with this guy"?
6
u/Tall-Introduction414 1d ago
More comments, please. I want to see a fucking novel around the code.
3
u/LegitimatePants 1d ago
My favorite comment of all time:
return SUCCESS; // success
3
u/MakeoutPoint 15h ago
Between this, and the crowd who thinks "a 7-way stop is self-documenting for a real dev", I'll take the comment.
2
u/serge-mv 1d ago
I had one class in college where we had to write comments like these or have points off. Most of the assignments were very short and very simple and didn't actually require comments, but comments were a part of the grade, so we had to do this kinda thing.
1
u/StanknBeans 1d ago
My comments would more so be like "slow traffic in this direction to avoid T-bone collisions"
1
u/Sion899 1d ago
A necesarry evil
1
u/Wynnstan 1d ago
Microsoft automatically generated help documentation in a nutshell.
1
u/_Weyland_ 1d ago
I did not do this on my DBT models before taking a 3 week vacation and letting a senior dev take over it.
Now I really wish I did comment the dumbest stuff.
1
u/_spinkey 1d ago
it's also not blue
1
u/Successful_Noise_347 1d ago
// TODO: add a comment explaining the comment below // the comment below explains the comment above
1
u/Runrun_5 1d ago
"This stop sign has eight glorious sides"
1
u/ComfortableTreat6202 1d ago
and honestly im thankful for it
1
u/jace255 1d ago
I do not tolerate this shit
1
u/Random-num-451284813 1d ago
When linters requires docblocks
1
u/Stjerneklar 1d ago edited 1d ago
yup, meanwhile there is no explanation for the light above the sign and if this was my really old code the light would just be there because i cant figure out how to get the sign to work without it... perhaps because its inside the light markup which is also why i needed the comment...
that or the sign is in typescript
1
u/Civil-Cookie-1659 1d ago
So true
1
u/Massepunkt_m1 1d ago
No sign without a story. From personal experience people probably keep ignoring that sign. We have about three signs in our bathroom informing you about the existence of a toilet brush and begging people to use it, but still, somehow, that doesn't seem to be enough. Sometimes you just don't know how to get any more clear
1
u/da_dragon_guy 17h ago
This sign indicates that there is a stop sign above it.
1
u/JoshTheJamFam 13h ago
I need this when im tired haha.
1
u/ProsodySpeaks 9h ago
'Sign not in use' on the big led signs over motorways is a great one too. I also enjoyed "beware distractions" after finishing being distracted by it.
0
u/shinitakunai 23h ago
Learn to use comments that matter. As example mines are like this:
Comments must enrich the info around WHY you made that code. Not what the code does
0
u/Ulrar 20h ago
I tell it to stop labelling a cat a cat, since that meme I believe I saw here. It actually helps
201
u/[deleted] 1d ago •
[removed] — view removed comment