Re: Commenting in Java
- From: Andrea Desole <news@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 10:20:26 +0200
Chris Uppal wrote:
But....
Did the software depend in any way of the prime-ness of HASHSIZE ? If so, was that obvious from the code alone (and not via an additional step: "Ah I recognise this as <such-and-such> algorithm, and I happen to know that only works well with primes") ? If not, then how would you have known that the author had made a mistake ?
I can tell the story of a similar mistake that I once made, that (had it not been caught by an eagle-eyed college -- who /read/ the comments and compared them with the code) might have had Very Serious Consequences for the company I worked for.
Redundancy is good. The /reason/ it's good is that errors can be detected, and ambiguities resolved. In the case of comments, that means that the possibility of divergence between code and comment is (one of the many) /advantages/ of commenting, not a disadvantage.
Redundancy is good when comments are correct. But if comments are wrong you might waste a lot of time trying to find out how the code can do what is told in the comment, when it's actually doing something different, For example, the author might have wanted, at the beginning, to use a prime number. After that he changed his mind, but not his comment. This makes you think "why did he put this comment? 51 is not prime. And why would I need a prime anyway?" (by the way, why do I need a prime? Is it related to the hash size?). Of course, you also think "maybe the comment is wrong", but you just spend more time checking and rechecking that you understand the code correctly, and that the comment is wrong. Not to mention, of course, the case when you trust a wrong comment.
Now, don't misunderstand me, I like comments, and documentation. But comments do have a drawback. Comments are good, too many comments sometimes are not.
.
- Follow-Ups:
- Re: Commenting in Java
- From: Chris Uppal
- Re: Commenting in Java
- References:
- Commenting in Java
- From: js_dev
- Re: Commenting in Java
- From: Mike Schilling
- Re: Commenting in Java
- From: Roedy Green
- Re: Commenting in Java
- From: Eric Sosman
- Re: Commenting in Java
- From: Chris Uppal
- Commenting in Java
- Prev by Date: Re: Commenting in Java
- Next by Date: Re: Commenting in Java
- Previous by thread: Re: Commenting in Java
- Next by thread: Re: Commenting in Java
- Index(es):
Relevant Pages
|