r/ProgrammerHumor • • 1d ago

Meme commentsExplainingTheComments

Post image
4.1k Upvotes

77 comments sorted by

117

u/Western-Anteater-492 1d ago
def addOne(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.
    return number + 1


def processData(data):
    return [
        (lambda x: (lambda f: f(f, x))(
            lambda f, n: 1 if n < 2 else n * f(f, n - 1)
        ))(abs(v)) ^ (i << 2)
        for i, v in enumerate(data)
        if (v & (v - 1)) != 0
    ][::-1]


def returnNumber(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.
    return number 

18

u/bluefishcrab 1d ago • Bravo

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.

16

u/AnUglyScooter 1d ago

Are you my coworker

5

u/parsonf 20h ago

It's ok, the middle one is self documented

2

u/Western-Anteater-492 19h ago

Yeah. Also it was hard to write...

4

u/sligor 1d ago

Missing for processData:

never touch this

2

u/gbchaosmaster 1d ago

It’s self-documenting, really. Just read it /s

2

u/BugFeaturesOnly 21h ago

Meanwhile, the 400-line regex right below it has zero comments and a single // good luck.

2

u/mossy_stile 16h ago

needs a 40 line docstring explaining what + 1 does

133

u/YnkDK 1d ago • Bravo

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.

31

u/trullaDE 1d ago

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.

16

u/AlShadi 1d ago

needs more emojis

15

u/SmoothLiquidation 1d ago

⚠️✅✅✅

15

u/KevlarToiletPaper 1d ago

You forgot a shitty metaphore.

"You can think of a STOP sign as a waiter telling you that you can't go inside the restaurant until you make sure that there's a table you can take."

2

u/theotherdoomguy 20h ago

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

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

13

u/Rabbitical 1d ago

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!

6

u/zeddash 1d ago

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.

6

u/hughperman 1d ago

Yes, the comment should be "Stop here so you don't crash into another car because they have priority"

0

u/zeddash 1d ago

Nah, that'd be an unnecessary comment as the "why" is obvious, as it's a verb. Verbs are so overlooked in function names.

4

u/SmoothLiquidation 1d ago

"Added this stop sign because Joe kept tearing through this intersection without looking".

2

u/hughperman 1d ago

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.

7

u/MaskedBandit77 1d ago

Please stop bullying me.

7

u/bluefishcrab 1d ago

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?

2

u/Makonede 1d ago

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

1

u/Makonede 1d ago

i'm not saying that just because i've never seen it happen, it doesn't happen, to be clear. i'm genuinely curious where this confusion could arise

1

u/bluefishcrab 1d ago edited 22h ago

You can see it in game code and performance tooling.

1

u/BugFeaturesOnly 21h ago
// increment i by 1
i++;

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

15

u/Western-Anteater-492 1d ago

That's every of my git trees...

  • feat: add XYZ
  • docs: updated missing hyperlink
  • fix: refactor
  • fix(docs): typo
  • fix: type mismatch
  • intermediate: still doesnt work, getting tired
  • WHYYYYYYYY
  • fix: somehow fixed the thing, will cleanup branch tomorrow
  • I don't cleanup the branch

6

u/Hadrian23 1d ago

Stop spying on my work.

1

u/Makonede 1d ago
  • WHYYYYYYYY

ci fail, not conventional commits. try again

6

u/Tall-Introduction414 1d ago

Commented curse words are a sign of blood, sweat and tears put into the development process. I am in favor.

4

u/scfoothills 1d ago

1

u/BedSpreadMD 1d ago

I'm out here carrying all the fucks in that chart.

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 

4

u/Makonede 1d ago

this is a terrible comment, why would you ever write this??

you should make it clear what it is you're doing with the success, not just that the success exists!

return SUCCESS;  // Return 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.

2

u/mxzf 1d ago

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.

1

u/KawaiiMaxine 1d ago

I liked that cause it teaches you how to explain your own code

2

u/serge-mv 1d ago

You like describing what print("hello") and read(file) does?

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

# Business requirement ticket-1324  
mypieceofcode()  

# complience with law whatever-123
budget = invoiceexample * tax  

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

1

u/Logogram_alt 19h ago

Tell what?

1

u/Ulrar 18h ago

The LLM. That's what the OP is almost certainly about

1

u/Logogram_alt 18h ago

I thought this post was about programming

201

u/[deleted] 1d ago • Regret

[removed] — view removed comment

62

u/IslayProgrammes 1d ago

I will not apologise

25

u/thekamakaji 1d ago

"I will not apologise".replace("(?<=n)\w+", "ever")

10

u/Traditional-Fix6865 1d ago

I will neverot apologise?

8

u/NextLevelAnon 1d ago

I only put comments where I want you to look…

4

u/serge-mv 1d ago

It's clearly simple and self-evident and requires no comments.

2

u/HomicidalRaccoon 1d ago

I always comment my regex like so:
// Abandon all hope, ye who enter here.

1

u/GTurkistane 1d ago

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.

-10

u/ThomasHardyHarHar 1d ago

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.