Click here to Skip to main content
15,886,362 members

Survey Results

Are you a Code Hoarder?

Survey period: 24 Jun 2013 to 1 Jul 2013

Do you have difficulty getting rid of unused or obsolete code? (Suggested by Andreas Gieriet)

OptionVotes% 
inactive code can be useful in the future, so I comment it out instead of removing46340.51
Inactive code clutters up active code, so I remove it instead of simply commenting it out68059.49



 
GeneralInactive code clutters up active code, so I remove it instead of simply commenting it out Pin
SOHAM_GANDHI4-Feb-14 22:39
SOHAM_GANDHI4-Feb-14 22:39 
Generalno comment please Pin
Philip Stuyck29-Jun-13 2:26
Philip Stuyck29-Jun-13 2:26 
GeneralRe: no comment please Pin
w-peuker1-Jul-13 0:16
w-peuker1-Jul-13 0:16 
GeneralIf you commit commented out code, please tell why it's commented out... Pin
Andreas Gieriet27-Jun-13 10:18
professionalAndreas Gieriet27-Jun-13 10:18 
The whole story is about maintainability of the code base.

I'm also tempted to comment out code once in a while, especially when I'm elaborating on some algorithm in an early phase. If I commit commented-out code, I regard it crucial to tag it with e.g.
//TODO: AGi/2013-06-27: this was experimental code. To be removed ASAP.<br />
// if (...) { ... }<br />
// ...<br />

Commented-out code without TODO tag is a no-go for me. Reasoning: when you or someone else comes back to that commented code block, you have no means to understand under which conditions this code might become active again.

Beside that, there are better and worse ways to "comment-out" code, depending on the language, e.g.
C#
...
// Statistics s = calculateStatistics();
// dumpStatistics(s);
...
/*
Statistics s = calculateStatistics();
dumpStatistics(s);
*/
...
if (0)
{
  Statistics s = calculateStatistics();
  dumpStatistics(s);
}
...
#if 0
Statistics s = calculateStatistics();
dumpStatistics(s);
#endif
...

...you name them...

I prefer, if at all, the first one (//...). The editor colors the comments such that it is obviously inactive.

The second comment (/*...*/) breaks if nested.

The third approach (if (0) ...) usually does not get coloring support from the editor and you have to constantly maintain it since the code still has to be correct.

The forth approach (#if 0 ...) may also lack editor support too but at least, the code does not need to be correct.

Now, what is the motivation to comment out code:
a) hoarding (it may be useful in some far future...)
b) short term fallback (backup since I'm not sure yet if the alternative code works)
c) some debugging/testing aid (uncomment code if debugging/testing)
d) other?

Case a) usually cost you more than it helps. If you really think that this code may be useful again: did you ever happen to re-activate such code? My observation is that hoarded code very very rarely gets re-activated. Reason: the code base in that far future will have changed so much that writing from scratch usually leads to a more sound solution than trying to squeeze the "old" code into the new code base. Alternative: remove that obsolete code and commit with a decent version control comment, like: removed experimental code for algorithm xyz.

Case b) is reasonably useful, but if committed, please add a TODO tag.

Case c) is really dangerous! I've seen go such code undetected into the product being only detected very late that it was activated by accident. My advise is to find other ways to control such code, e.g. by #if CHECKED_RELEASE (included/excluded at compile time) or if (validate) ... (activated at runtime, e.g. via command line args) or similar means. This case c) is sometimes observed as crude alternative to proper Dependency Injection: "for debugging/testing use another object than for productive code", etc.

So:
1) try to avoid commented out code by removing it ASAP (with a decent version control comment)
2) if there is commented out code, tag it with a resonable TODO
3) follow up frequently on TODOs, i.e. go to 1) (remove that commented out code Wink | ;-) ).

Cheers
Andi
GeneralComment, wait, delete PinPopular
Giuseppe Tollini26-Jun-13 11:31
Giuseppe Tollini26-Jun-13 11:31 
General+1 Pin
imagiro26-Jun-13 20:40
imagiro26-Jun-13 20:40 
GeneralRe: Comment, wait, forget Pin
Doofenshmirtz27-Jun-13 4:04
Doofenshmirtz27-Jun-13 4:04 
GeneralCoincidence Pin
Colin Mullikin26-Jun-13 5:52
professionalColin Mullikin26-Jun-13 5:52 
GeneralDead Apps Pin
Mycroft Holmes25-Jun-13 19:46
professionalMycroft Holmes25-Jun-13 19:46 
GeneralI comment out code and add a comment Pin
Gabbie Seal25-Jun-13 18:32
professionalGabbie Seal25-Jun-13 18:32 
GeneralRe: I comment out code and add a comment Pin
AlexCode26-Jun-13 21:03
professionalAlexCode26-Jun-13 21:03 
GeneralDeprecated, then removed, and always under source control PinPopular
Marc Clifton25-Jun-13 13:21
mvaMarc Clifton25-Jun-13 13:21 
GeneralRe: Deprecated, then removed, and always under source control Pin
the retired25-Jun-13 14:15
the retired25-Jun-13 14:15 
GeneralFew people in programming give me more pleasure than... Pin
tec-goblin25-Jun-13 8:35
tec-goblin25-Jun-13 8:35 
GeneralIF I comment Pin
Joezer BH25-Jun-13 4:58
professionalJoezer BH25-Jun-13 4:58 
GeneralRe: IF I comment Pin
AlexCode26-Jun-13 21:09
professionalAlexCode26-Jun-13 21:09 
GeneralRe: IF I comment Pin
Joezer BH26-Jun-13 22:28
professionalJoezer BH26-Jun-13 22:28 
GeneralTwo words Pin
dan!sh 24-Jun-13 23:04
professional dan!sh 24-Jun-13 23:04 
GeneralRe: Two words Pin
Dennis E White25-Jun-13 20:30
professionalDennis E White25-Jun-13 20:30 
GeneralGot Git? Pin
Deus ex Machina24-Jun-13 13:07
Deus ex Machina24-Jun-13 13:07 
GeneralRe: Got Git? Pin
Marc Clifton25-Jun-13 13:25
mvaMarc Clifton25-Jun-13 13:25 
GeneralRe: Got Git? Pin
Deus ex Machina26-Jun-13 6:22
Deus ex Machina26-Jun-13 6:22 
GeneralRe: Got Git? Pin
Marc Clifton26-Jun-13 7:21
mvaMarc Clifton26-Jun-13 7:21 
GeneralRe: Got Git? Pin
AlexCode26-Jun-13 22:14
professionalAlexCode26-Jun-13 22:14 
GeneralBoth! PinPopular
DaveAuld24-Jun-13 4:50
professionalDaveAuld24-Jun-13 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.