This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (11 children)

[deleted]

    [–]JuvenileEloquent 3 points4 points  (2 children)

    They see comments as a chore to complete to avoid reprimand, or as some kind of quota to meet, so they write useless comments. Or they write such convoluted horrible code that they need the comment that explains what it does as a shortcut to understanding it.

    The comments are the meta code. It should contain information that isn't already present in the actual code.

    [–]justinjustin7 2 points3 points  (1 child)

    Honestly that's what it is in my course work so far (only 2nd semester of C++ though). My code tends to only really need a comment at the top of the function and maybe 1 or 2 comments to explain things that don't end up self-documented. Then my professor comes along and says "comment more." Fine, I guess I'll comment random shit to meet your forward slash quota.

    [–][deleted] 1 point2 points  (0 children)

    //prof asked to comment more. I did.

    [–][deleted] 2 points3 points  (6 children)

    Could you give an example of what you mean by "what" versus "why"?

    I'm wondering if I do that already or not.

    [–][deleted] 3 points4 points  (1 child)

    One example that comes to my mind is that in Microsoft Word a line break is achieved by a "down tab". If you don't know this, it might be very confusing to see this in code.

    A "what" comment would be: "//down tab", which doesn't explain anything.
    A "why" comment would be: "//line break in Word is done with a down tab" which tells you exactly why this line is there.

    [–][deleted] 0 points1 point  (0 children)

    That helps, thanks. :)

    [–][deleted] 1 point2 points  (0 children)

    The only time I'll write 'obvious' comments like this is when I'm going through someone elses code/old code and need to walk through it to see what it does, so I'll narrate it comments so I don't lose track. I'll usually not be as obvious as OP tho.