this post was submitted on 28 Sep 2024
1153 points (98.9% liked)

Programmer Humor

32263 readers
58 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 2 weeks ago* (last edited 2 weeks ago) (21 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 2 weeks 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 2 weeks ago

Doesn't need any comment:

int getCount() { return count; }

Absolutely needs a very extensive comment:

double getBojangleFlux { return fubar * .42; }

load more comments (19 replies)