Whenever I find out that a large portion of my code needs to be changed, either because it is incorrect or because it needs to be adapted to major architectural changes necessited by other reasons, this is what I typically do:
- I comment out all code that I suspect I might have to change. I treat the commented out code as a sort of my TODO-list.
- I gradually review the commented out code and uncomment parts of this code, or copy-paste them elsewhere and then edit them as necessary, or rewrite parts of this code from scratch, looking at the commented out code for reference. Whenever I think I'm done with a part of the commented out code I remove it.
- I continue this until I can see no more commented out code.
I should note that I'm largely doing this on the personal project that I'm developing alone.
However, I was told, that I should stop doing this. I was told that instead, I should start using git, referring to old commits to see old code, instead of leaving commented out code. I was told:
Commenting out code is a bad habit that should be wiped out. You lack experience so you fail to understand that. If, in a few years, you see code of another person who likes commenting out code, you will yourself start swearing at this person. Whenever I see commented out code, I remove it in its entirety, without even looking at it, because usually such code is completely worthless. You will certainly fail to see the downsides of commenting out code in small, one-person projects; but if you find a job and keep this habit there it will be a shame.
May I ask what are these downsides of what I'm doing that I'm failing to see now?
I must say I'm not really keen on only using git to see past code. As I said, I treat commenting out code as a sort of a todo-list; while git will show me how the code used to be looking, it will fail to clearly show me which parts of code are still necessary to be reviewed and which are already done. I fear I may miss some part of code and introduce bugs.
For completeness, I feel I should add that the person I'm quoting is an experienced developer and a fan of Uncle Bob's "Clean Code" - and Uncle Bob did criticize commenting out code harshly in his book.