Wednesday, July 18, 2012

Comments

Consider the following code:

//Increment data count here
dataCount++;

The developer responsible for this legacy code heard that comments are good. What he was not aware of is DRY (Don't Repeat Yourself) principle. It is obvious what the code does. What is not obvious is why it is incremented here and not at the end of the function. I'd like to know why it is incremented unconditionally. As maintenance developer I'd like to see variable name that clarifies what kind of data it counts. Unfortunately there is no comment to help me.

No comments: