Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you update ancient code comments that are wrong? [closed]

Tags:

comments

G'day,

Inspired by a comment I made in my answer to this question on commenting Perl regexps I was wondering the following.

When you are working on older, old, bloody ancient, code do you update comments that are out of sync with the code or do you just update the code and ignore the comments that are already "miles out" from the reality of the current code?

I guess basically approaching things from the "broken window" syndrome?

BWS basically says that people just say "stuff it" and don't take care to fix errors that are there if they see that people, already involved with the system in question, didn't care enough to fix these sorts of things. A totally pervasive mind set IMHO!

I'd be interested to see what other people "at the coalface" do.

cheers,

like image 746
Rob Wells Avatar asked Jun 12 '09 21:06

Rob Wells


3 Answers

I will absolutely fix bad comments.

Sometimes it is just to delete them so that they don't mislead.

Better still, I prefer to refactor the code so the comments are not necessary - self documenting code is better than comments because it can't get out of date.

like image 107
Chadwick Avatar answered Sep 21 '22 15:09

Chadwick


Recently I started following more of Uncle Bob's Clean Code advices and I'm trying to transform comments into functions that enclose (extract) the commented code in a function that is at least as meaningful as the comment it replaces.

like image 38
Otávio Décio Avatar answered Sep 21 '22 15:09

Otávio Décio


I always try to update them if I can, or at the very least add a note to the effect that they might be wrong. It's a worthwhile investment of a small amount of time.

The other thing I always do is add any relevant bug numbers, and what effect those edits had - that's always useful to see further down the line.

like image 20
RichieHindle Avatar answered Sep 21 '22 15:09

RichieHindle