More the merrier

alphacyberranger@lemmy.world to Programmer Humor@programming.dev – 1214 points –
76

You are viewing a single comment

I disagree. When comments are essentially just a rephrasing of the class/method name or arguments it is not helpful and anything that is not helpful is cluttering up the code and making it harder to quickly see what the code is doing. I'd rather have no comments than comments like that.

I reserve comments for explaining why a section of code is needed or explaining how a complex algorithm works.

i = 0; // Set i to 0 is pointless.

if (last_output_vertex[i] == bounds[i]->length - 1) contibuting_bounds[i] = NULL; // stop outputting a bound if the entire bound has been output is helpful.

I think even the second comment is not that helpful.

Just use (boolean) variables that phrase what your comment would explain, often more concise and better to read IMO. Also if the logic is more complex compose multiple named (boolean) variables. I think comments seldom make any sense at all (function doc is a one of the rare cases, mostly for the user of the library in the IDE).

Not to mention the code and comment will inevitably become inconsistent with each other whenever someone forgets to update both.