BIRT 3.7
Written by: Michael Williams
Featured Refcardz: Top Refcardz:
  1. Scrum
  2. Apache Maven 2
  3. Essential MySQL
  4. Node.js
  5. Groovy
  1. jQuery Selectors
  2. Ajax
  3. Java
  4. Spring Config.
  5. Java Concurrency

Link Details

Link 132853 thumbnail
User 225256 avatar

By mswatcher
via memeagora.blogspot.com
Published: Nov 11 2008 / 16:27

I am sometimes asked about my position on code comments, and, like most things, I have strong opinions about it. Two kinds of comments exist: * JavaDoc-style comments (which encompasses JavaDoc, XMLDoc, RDoc, etc), which are designed to produce developer documentation at a high level (class and method names and what they do)
  • 12
  • 12
  • 1312
  • 2

Comments

Add your comment
User 211643 avatar

zynasis replied ago:

0 votes Vote down Vote up Reply

the retorts by the other commenters are enough for me.

User 281050 avatar

cbang replied ago:

0 votes Vote down Vote up Reply

That's a dangerous advice. We're not exactly knows for our documentation and communication skills, and I would be scared novice developer read this title and go thinking all they need to do is code. You can have bad comments, sure. But learn how to write good comments (read Code Complete or Clean Code) rather than equate comments with code smell!

User 211643 avatar

zynasis replied ago:

3 votes Vote down Vote up Reply

yes, but this is coming from perfect world thoughtworks.

User 277934 avatar

jfpoilpret replied ago:

1 votes Vote down Vote up Reply

Although I generally don't agree much with this post, I find it an interesting read.

User 134694 avatar

alruiz15 replied ago:

0 votes Vote down Vote up Reply

Nonsense. I haven't seen code without comments that can be understandable for developers other than the author (and sometimes not even for the author!)

User 134694 avatar

alruiz15 replied ago:

0 votes Vote down Vote up Reply
User 237699 avatar

juulepuul replied ago:

1 votes Vote down Vote up Reply

I tend to agree with the guy.
To be honest.. comments have never helped me much in projects that I took over.
In fact.. they usually distract me..

You have to have a general idea what a project is supposed to do (high level design).
The rest is code reading+navigating for me. Code navigation is what REALLY helps speed up understanding a project for me.
(go to definition,find usages etc etc).

Javadoc style comments helps in libraries though. But those are more like integrated help-files.

User 211643 avatar

zynasis replied ago:

0 votes Vote down Vote up Reply

i believe the mantra is the tests are the documentation. but all the tests document is the behavior, NOT the motivation or purpose of that behavior.

User 211543 avatar

rob.desbois replied ago:

1 votes Vote down Vote up Reply

I disagree that comments == smell, but I'm in favour of making code self-documenting as far as possible. Turning large functions into many smaller functions does make everything easier to read, and I'm guilty of not doing this enough.

On the subject of using tests to document a system I disagree. They can show *how* to use it, but not why. They don't imply rationale. It is much easier to read through some well-written javadoc/equivalent documentation for methods and classes as an introduction than to read through the tests. Especially if your test-writing skills are relatively poor like mine :-(

Nonetheless this is a good post that provides some food for thought and is worth a read.

User 211643 avatar

zynasis replied ago:

2 votes Vote down Vote up Reply

i agree, but the responses are much more worthwhile to read.
so if your short on time, skip over the blog and spend time on the responses.

User 265881 avatar

Topnotch replied ago:

1 votes Vote down Vote up Reply

You've hit the nail on the head here. The big problem here is the author doesn't acknowledge the fact that comments should aways tell WHY not how. Proper use of comments mixed with clear code shoud be the ultimate goal of all developers. I recently purchased his book and its good but thinking that all comments = code smell is short sighted at best. Unfortunately, some developers will use the advice given in this post to justify lazy coding completely lacking in comments of any kind; much to everyone's detriment.

User 211643 avatar

zynasis replied ago:

0 votes Vote down Vote up Reply

i work with some thoughtworks contractors every day, and every day i argue for "why and when to use" comments...
sigh, i just cant seem to get through to them

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.