views:

48

answers:

5

As I work on a code base there always comes a time when an old rule or some bit of functionality needs to be removed. I often simply comment out the code that needs to be removed. However I wonder whether I should simply delete the lines of code that need to be removed or leave them in? Any recommendations? Thanks!

+10  A: 

Delete them. This is especially true if your code is under source control. If it isn't, start there right away. Leaving them in is cruft.

Audie
+3  A: 

I tend to first comment things out (just in case I immediately realize I needed something from that part), and a few commits later remove it completely. If someone needs something from the removed part later, they can always get the old version from source control. Whether you leave stuff in for a while or not is up to your own preference, but as long as it exists in source control, it should be safe to delete it immediately.

Matti Virkkunen
+1  A: 

In general, the consensus here has been on the side of "remove the code." It cleans things up, and you can always recover it later, if necessary, from source control (and you are using source control, right?)

Beska
+2  A: 

Remove it. That's (a tiny part of) why you use version control; you can always get the code back if you really need to. And you hardly ever do. With comments, you're just polluting your code, making it harder to understand.

Carl Manaster
A: 

IMO that is one use of source code control. I prefer to have active code in my projects.

gbogumil