Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to put comments about bug fixes in the source code?

And if so, where do you draw the line? My coworkers and I disagree on this subject. I have seen such things as

// fixes bug # 22

to

// fixed bug: shouldnt be decrementing
i++;

Is it ok if the change is fairly significant, and radically changes what the method was written to do? Or do you simply change the summary text of the method to reflect what it is now meant to do?

My opinion is that this information should be put into source control. Some state that this is bad because then it will be lost outside of the context of source control (say you switch systems and want to keep historical data).

like image 332
esac Avatar asked Dec 09 '09 22:12

esac


2 Answers

Comments should explain how the methods work.

Source control explains why changes were made.

like image 137
sh-beta Avatar answered Nov 08 '22 01:11

sh-beta


Adding a comment about bug fixing is a good idea, if you write the right thing.

For example,

/* I know this looks wrong, but originally foo was being decremented here, and 
   it caused the baz to sproing. Remember, the logic is negated by blort! */

Stuff like Fixes bug #22 is better kept in source control. Comments in your code should be signposts to help future sojourners on their way, not satisfy process and tracking.

like image 45
erickson Avatar answered Nov 08 '22 00:11

erickson