This may be better in the polling booth, but I'm curious what you all think about or have experienced (and I want to vent a little). First the question, then the venting.

Is it good or bad to leave commented-out code in production? Why?

I think it is bad. Why? In the code-maintenance phase, it's often difficult enough to figure out the intent of the executing code. The difficulty is compounded if you have to sort through code that was executing at one point in time.

I've seen this where I work, and it annoys, frustrates, sometimes confuses me, for the reason cited above. (If you ever work with me on any project an notice me doing this, slap me. :-)

Update: It looks like there are more votes for "it's bad" than for "it's good", which makes me :-). perrin, followed by others, mentioned one (and in my opinion, after considering it, the only) justifiable reason for leaving in commented-out code:

...leave it in commented out with a note saying "This looks like it should work, but it doesn't because XYZ." That could save other coders from duplicating this effort.

(My emphasis added.) I like dragonchild's idea even better: instead of commenting out blocks of code, remove the code, and put the algorithm that didn't work in the comment.

And now to possibly offend some of you, I don't agree with the "leave functionality commented out now that the users may ask for later" argument. My experience has been that by the time the user asks for the functionality I thought would "be cool" to have, what they're asking for is different enough to justify a re-write of what I was thinking the first time through. Sorry...

Still, the famous clause "it depends" applies in this case too. (That's been the ultimate answer to several of my posts. :-)


In reply to Commented out production code? by t'mo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.