Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad practice to leave commented-out code in production releases

Tags:

I regularly see production code from developers (large companies and individuals) that contains code that has been commented out. Presumably this removes earlier attempts at achieving the functionality that didn't work for some reason.

To my mind, this is messy, but potentially has some benefits e.g. on returning to refactor or extend the code, the developer can see what has been tried previously.

Are there any security or best-practice aspects to this?

like image 778
Jonathan Day Avatar asked Sep 08 '10 02:09

Jonathan Day


1 Answers

Best practice is to use SCM. If you think the old code is really something people will want to refer to in the future, leave a comment of "// We used to do it another way, which had interesting property X -- see revision 103" rather than leaving whole chunks of code that don't do anything.

Commenting out code has its place, but that place is quickie tests that aren't even worth the time to do a branch.

If the code is worth keeping, it's worth more than being lost in a comment somewhere. If it is not worth keeping, kill it with fire.

like image 86
Chuck Avatar answered Sep 27 '22 20:09

Chuck