Delete commented-out code

You may see it the source code of nearly in every software project: commented-out code. Maybe you ignore and read over it or maybe you ask yourself: Why does this commented-out code exist? Does the creator of this code store it for any reasons? What should I do with this code?

In my opinion the answer is very simple: Delete commented-out code immediately!

Of course, you will delete something someone other has created. And you may hurt this person if you delete his work. Therefore you should try to make a common agreement within your project team: Whenever someone sees commented-out code he shall delete it.

Why does this code exist? I think the only reason is because someone has implemented a change and would temporary store the origin code as possibility to go back to the old version. That’s ok, but as soon as the new implementation is done the old source code is no longer needed. So the commented-out code should not be checked in to the source code control system. If someone wants to go back to the origin version, the code stored in the source code control can be used.

But why is this commented-out code so dangerous? Because the code sits there and rots. It is getting less and less relevant with every passing day. It uses variables which no longer exists, calls functions which have been changed or it follows obsolete conventions. In other words: it is a very code source for errors in case you reactivate the code or use parts of it. Furthermore it may confuse everyone who reads it because everyone will ask itself why this source code exists.

Therefore, in my opinion, you should talk with your team about this topic and make the agreement that everyone who sees commented-out code shall delete it immediately without reading it.

Dieser Beitrag wurde unter Uncategorized veröffentlicht. Setze ein Lesezeichen auf den Permalink.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

Du kommentierst mit Deinem Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s