Comments on comments - No Fluff Just Stuff

Comments on comments

Posted by: Venkat Subramaniam on January 17, 2006

If you think you need to comment your code, think again.

There is a difference between documentation and commenting.

A documentation states what a method does, and it resides outside code blocks.

Often, comments are used to explain how a piece of code works. If a method is written
well, then do you need the comments?

If I show a piece of code that is confusing, you can (a) write a comment to describe
how, or (b) refactor the code so it is obvious what it does.

Option (a) may result in further confusion. Also, when writing comments, I have seen
developers pour their emotions and opinions, which serves as distraction and takes us further
away from understanding the code.

Option (b) can help not only make the code easier to understand, it can help us make it simpler.
There is beauty in simplicity.

In the wise words of C.A.R. Hoare, "There are two ways of constructing a software design.
One way is to make it so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies.
"

Back to writing comments.

Writing comments is like explaining a joke. Good code, like good jokes, have to
be left for the reader to absorb (and enjoy).

Venkat Subramaniam

About Venkat Subramaniam

Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., creator of agilelearner.com, and an instructional professor at the University of Houston.

He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is a regularly-invited speaker at several international conferences. Venkat helps his clients effectively apply and succeed with sustainable agile practices on their software projects.

Venkat is a (co)author of multiple technical books, including the 2007 Jolt Productivity award winning book Practices of an Agile Developer. You can find a list of his books at agiledeveloper.com. You can reach him by email at venkats@agiledeveloper.com or on twitter at @venkat_s.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »