|No such thing as a small change|
Re^5: Why no comments?by gone2015 (Deacon)
|on Feb 02, 2009 at 15:16 UTC||Need Help??|
Thanks for the comments.
It appears there is little common ground on which to base a discussion, but since you picked out two examples, I'll address those briefly, and then not waste any more of the monks' time.
For me, the writing of comments is part of the thinking process. The comments you commented on were (if memory serves) written before the code, as I was sketching out what needed to be done. I agree that comments that do no more than repeat what the code says are not only redundant, but can simply be clutter (except where the code is particularly tricky) -- for me the key is to concentrate on the "why". Though I do find it useful to use comments to point up the stages that a block of code goes through.
The first comment you picked out:
served several purposes: (a) it was a stage in the subroutine; (b) the algorithm used depends on stuff being reverse sorted, this is key to understanding what is going on; (c) it's doing something a little tricky: in the resulting array entry 0 is not the same as the other entries, it's the sum of those entries. While I was writing it, I thought about all this... I suppose I could have written a longer comment to emphasise the key points...
The other comment you picked out:
(sorry about the spellin error)... well, yes, it's not the most significant of the comments in a 2,800-odd line module. Again, the subroutine was broken into stages, so this also serves as the end of the previous stage. The order in which the partitions are returned is key -- the caller can (and does) depend on this.
As it happens, there are three similar subroutines, with the same general shape, and the comments emphasise that. You've commented on the smallest of the three, where there is less to comment on.