Question

If I'm maintaining a code base and want to replace some code, should I just erase it, make a comment on the change and why it was replaced, and implement the new code? Or should I comment out the section of code that I'm replacing, state why and put the new code in? I can see doing the latter when you are sacrificing speed for memory, or vice versa, but are there other situations where the latter would be recommended?

Was it helpful?

Solution 2

These are my recommendation:

  1. Assuming this is properly version controlled, you should just replace the code. That's the beauty of version control system, you can rollback to a previous change.

  2. If possible make the code self documenting rather than put comments in there to explain.

  3. I don't recommend commenting out the code, if you have version control, as it probably won't be cleaned up and leaves guess work for anyone later. They'll probably think there is a reason why that code is commented out.

  4. Ensure all your code is properly tested before committing.

OTHER TIPS

You probably should just remove old code and put new code. You should add comment into the code only if new code ought to be commented itself. Description of what was removed, what was added and why should be in comment message in your version control system and in your task/issue tracker.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top