this post was submitted on 06 Jul 2024
1090 points (99.5% liked)

Programmer Humor

19623 readers
507 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 58 points 4 months ago (4 children)

Comments should explain "why", the code already explains "what".

[–] [email protected] 47 points 4 months ago* (last edited 4 months ago) (2 children)

The allowable exception is when the what is a what the fuck, as in you had to use a hack so horrible that it requires an apology comment

[–] [email protected] 9 points 4 months ago

Absolutely, although I see that as part of why

Why is there a horrible hack here? Because stupid reason...

[–] [email protected] 3 points 4 months ago

Describing the what also helps when you dabble in a new technology or little-used technology. It helps to explain to yourself what you’re doing and it helps in onboarding. “Hey, newbie, there’s a function in XYZ module that’s extensively documented. Look there for guidance.”

[–] [email protected] 21 points 4 months ago (1 children)

Inline comments yes.

Function/Class/Module doc comments should absolutely explain "what".

[–] [email protected] 6 points 4 months ago (1 children)

You are absolutely right. It was inline comments I had in mind.

[–] [email protected] 5 points 4 months ago

I don't code, at best I script. I'm a sysadmin, not a dev, so I play around in PowerShell mostly.

I just started to naturally do all of this. Not because I was taught to, but because I've written too many scripts that I later looked at, and thought, WTF is going on here.... Who tf wrote this? (Of course it was me)...

So instead of confusing my future self, I started putting in comments. One at the beginning to describe what the file name can't, and inline comments to step me through what's happening, and more importantly why I did what I did.

The sheer number of comments can sometimes double the number of lines in my script, but later when I'm staring into the abyss of what I wrote, I appreciate me.

[–] [email protected] 4 points 4 months ago (2 children)

Unless you're working with people who are too smart, then sometimes the code only explains the how. Why did the log processor have thousands of lines about Hilbert Curves? I never could figure it out even after talking with the person that wrote it.

[–] [email protected] 3 points 4 months ago
[–] [email protected] 1 points 4 months ago* (last edited 4 months ago)

If you know how the code does something, you also know what it does.