«« Next » « Previous
«« Next » « Previous

Link Details

Voters make better lovers! Login and vote now.
Link 10769 thumbnail

By bloid
via it-gears.blogspot.com
Published: Jan 09 2007 / 20:37

Why don't developer comment their code? This is a question I will try to answer by summarizing my life experience.
  • 35
  • 0
  • 3474
  • 1096

Comments

Add your comment
User 208391 avatar

BenRose3d replied ago:

2 votes Vote down Vote up Reply

On the blog, Bill stated, "Documentation obfuscates code, it describes what the author thinks the code will do, and not that what really happens at runtime."

I would like to respond to the statement, not really the individual, here. Documentation does describe what the author thinks the code will do, but more importantly, it describes what he or she wants it to do. This makes it easier to spot where someone made a mistake.

When setting out to create a class or method, I personally find it useful to comment for everything I intend to do. I then write the code around the comments. Often I just delete them, but in other cases, it serves me well to leave some there.

Comments are especially usefull when working in a framework you had no part in planning or creating. "Why did they use this when they could have used that?" You don't know unless there's a comment there. It doesn't mean the comment is necessarily correct, but at least it gives you a sense of what the author had in mind.

User 181930 avatar

jwenting replied ago:

0 votes Vote down Vote up Reply

OTOH commenting too much causes problems of its own.
If the code is garbage, and worse the comments in it don't reflect the code you have a hell of a time figuring out what's going on.

Had that more than once. A piece of code is broken, the comments on it are broken as well but in a different way.

User 214401 avatar

stanislavb replied ago:

0 votes Vote down Vote up Reply

Actually it depends on a hell of a lot things but!
Commenting code is necessary!
The thing that bothers most of the people when commenting is that they might do the code block well (I mean self documented code here) and for example put in a comment but if the code is procedural style it will really change overtime!
In OOP this wont happen so easily so comments in procedural style might become pain in the ass while in OOP they are a good practice!

Recommend reading about XP (Extreme Programming)!

Cheers!

User 179375 avatar

Ricky Clarkson replied ago:

0 votes Vote down Vote up Reply

Finally I agree with jranting on something.

It's similar to the old trick of trying to say the colours that some words are printed in. Easy until the words are also colours, but unrelated colours. (HTML would help here!)

I very rarely comment code, because the compiler doesn't tell me when the comments don't reflect the code. Source code is not a place to put stuff that the compiler won't be parsing.

I'd rather make my source code look how the comment would, if I did write it, or as close as possible.

User 210294 avatar

satov replied ago:

0 votes Vote down Vote up Reply

I'm totally on point no 2. Good code needs very little comments, in key points.

User 204089 avatar

hiveminds replied ago:

-1 votes Vote down Vote up Reply

Code is not commented for the same reason that people j-walk. It's not important until you get caught or run over. Then it's too late.

User 179375 avatar

Ricky Clarkson replied ago:

-2 votes Vote down Vote up Reply

-1 bad analogy

User 160328 avatar

levent replied ago:

0 votes Vote down Vote up Reply

I like commenting codes :).. Without comments, i dont feel the job is done perfectly.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.