8

Recently I took a look at some code I'd committed to our version control system at work, and I found a bunch of it had been replaced (that's OK) but the old version was still there, commented out.

I guess the guy felt a bit "insecure" about deleting it, and therefore left it there commented out. However, that's not necessary, as we are using version control. (The old version was wrong, so it's not like it's going to be needed in the future.)

These stackoverflow questions deal with the question of if leaving old code like that around is a good idea or not:

However, my question is: is there a term for this sort of thing, or an "anti-pattern name" i can quote when talking to my colleagues about it?

Community
  • 1
  • 1
Adrian Smith
  • 17,236
  • 11
  • 71
  • 93
  • The question is covered pretty well at http://stackoverflow.com/questions/758279/checking-in-of-commented-out-code – tawman Feb 15 '11 at 16:10

4 Answers4

3

The Anti Patterns book calls this the Lava Flow antipattern, in which old, unused code remains in the code base, whether it is commented out or not.

Chin Huang
  • 12,912
  • 4
  • 46
  • 47
  • 1
    True, but I think there's a difference between code which could still be callable (even if it isn't) and might even work, and code which is known to be wrong and thus replaced (and, in this anti-pattern, is still included in the source, commented out.) – Adrian Smith Feb 15 '11 at 16:25
3

"Litter."

This is a term I use personally. As far as I know, it is not a recognized pattern name. But then, I don't recognize any of the others listed here. "Litter" communicates the concept and its worth immediately to those who have not read of the cute, obscure names.

Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
1

I've seen it referred to as an "unforgivable sin" but there's no formal name that I am aware of.

It could also lead to Duplicated Code, Long Method, or Large Class Code Smells if you consider commented code to have a scent. (edit again) Actually, the more I think about, "Bad Comments" should itself be a code smell. Commented code without any sort of explanation certainly isn't a helpful "comment."

Isaac Truett
  • 8,734
  • 1
  • 29
  • 48
  • 1
    I don't know a formal name for it either, surprising as it happens a lot in my experience. Why do people do these things! – Robin Salih Feb 15 '11 at 16:10
  • @Robin: If you see you need this commented-out code again, it is easier to uncomment than to search the right old version, check out only this one file and merge it back. If you even remember that there was an old version. (This is not to defend this practice, but simply a answer to the "Why", even if it had no question mark.) – Paŭlo Ebermann Feb 15 '11 at 16:14
1

Wikipedia records this anti-pattern under the name Boat Anchor. Though I can't say I ever came across that usage before I just googled for it.

Chris Dickson
  • 11,964
  • 1
  • 39
  • 60
  • True I came across that term as well, although I'd never heard of it before I searched! But alas it refers to code which is no longer called (but could be called, in principle, and might also work), as opposed to code which has been commented out (as the code had a bug or something). – Adrian Smith Feb 15 '11 at 16:19
  • 2
    Boat Anchor seems to refer to "live" code that serves no functional purpose, at least given the example on the Wikipedia page (a variable declared and initialized, but never references again). I think there's a subtle difference between that and code that is simply commented out in blocks. – Isaac Truett Feb 15 '11 at 16:20