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

By Adrian Smith12 Jan 2016200 words1 mins to read

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 was written by Adrian Smith on 12 Jan 2016

Follow me: Facebook | Twitter | Email

More on: Coding | Project Management | VCS