this post was submitted on 28 Sep 2024
1162 points (99.0% liked)

Programmer Humor

32479 readers
223 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 21 points 1 month ago* (last edited 1 month ago) (22 children)

Asking as a newbie programmer: how do you suggest we write comments that explain the 'why' part of the code? I understand writing comments explaining the 'what' part makes them redundant, but I feel like writing it the former way isn't adding much help either. I mean, if I created code for a clock, is writing "It helps tell what time it is" better than writing "It is a clock" ?

It would really help if someone could give a code snippet that clearly demonstrates how commenting the 'correct' way is clearly better than the way we are used to.

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

Not everything needs a comment - knowing when comments add value is the key... "what" vs "why" is usually a good indicator but some code just doesn't need a comment.

[–] [email protected] 3 points 1 month ago

Doesn't need any comment:

int getCount() { return count; }

Absolutely needs a very extensive comment:

double getBojangleFlux { return fubar * .42; }

load more comments (20 replies)