1505
you are viewing a single comment's thread
view the rest of the comments
[-] mundane@feddit.nu 70 points 1 week ago

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

[-] calcopiritus@lemmy.world 27 points 1 week ago

Inline comments yes.

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

[-] mundane@feddit.nu 8 points 1 week ago

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

[-] MystikIncarnate@lemmy.ca 6 points 1 week 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.

load more comments (1 replies)
load more comments (9 replies)
this post was submitted on 06 Jul 2024
1505 points (99.4% liked)

Programmer Humor

18388 readers
489 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