this post was submitted on 24 Oct 2023
711 points (97.6% liked)

Programmer Humor

19589 readers
578 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] 60 points 1 year ago (14 children)

Commenting well is a highly advanced skill. I generally prefer no comments on code since it's less likely to confuse people and I'll merrily purge auto-doc comments and anything like

// getId() returns an id

That comment has negative value.

[–] [email protected] 9 points 1 year ago (4 children)

Comments should only be used to describe stuff that’s otherwise difficult to convey with code.

[–] [email protected] 18 points 1 year ago (1 children)

The best explanation I've ever heard is:

Comments should state the 'Why' never the 'What'.

[–] [email protected] 1 points 1 year ago

There are some cases though where the code is just complicated for reasons outside of your control, in which case "what" comments are good - but they should never be taken at face value, but only used as a first step in understanding the code. There's a significant risk of the code not actually doing what the comment says.

load more comments (2 replies)
load more comments (11 replies)