Don’t leave old out-of-date code commented out; just delete it

If you replace code, and commit out the original while you are working, please delete the commented out code before you commit.

Code such as:

int x = foo() + 1;
// int x = foo() + 2;

Becomes pretty unreadable after a time.

It makes sense to you while you write it, but in 2 years, and looked at by another developer, it will probably not make any sense.

We all use Subversion or git etc., so if you do realize you need the old version at any point in the future, it's still there.

And this is a good point too:

If it's commented out, then it may rot: when you suddenly decide that you need it again, you realise that it no longer compiles, or needs to be rewritten to make it fit with other things that have changed in the meantime.

So you can delete away without fear :)

This article is © Adrian Smith.
It was originally published on 12 Jan 2016
More on: Coding | Project Management | VCS