4

Recently I came across this question where the user posted an answer and then, upon clarification from OP, revised his answer and code. The user then kept the old code in the answer but put the <strike> html tag to strike-through the old code.

Is this a good practice or should old code be removed when replacing it with updated code?

Edit History of Answer

1

1 Answer 1

12

In the past, I used to ask people if they would ever do this in their own blog, but I stopped asking this because some people actually think things like this are clever or cute.

So I will offer this principle instead: Would you ever see this in a newspaper article?

No, you wouldn't. Ergo, it doesn't belong in an answer either. Answers should be the finished product, not some collage of editing attempts. If you want to see that, look at the edit history of the post.

8
  • 6
    Programmer analogy: Would you leave old code commented out in your production code base when you write new code? Commented Oct 6, 2014 at 18:06
  • 2
    I pretty much agree with this, except I have used it myself. I posted an answer, made a huge assumption in one of my sentences, and then striked it out once I realised it wasn't necessary. I left it there as I felt it added to the answer, the kind of "this was my train of thought, but no, so if you think the same, you're wrong". I kind of regret it, it doesn't format nicely, and it could do without being there. That said, why do we have the ability to use it all if answers should be the finished product?
    – Joe
    Commented Oct 6, 2014 at 18:47
  • 2
    @Joe: Markdown is a tool, not a mandate. Like most tools, it gives you the ability to do certain things, but lets you decide whether to do good or bad things with it.
    – Robert Harvey Mod
    Commented Oct 6, 2014 at 18:51
  • @RobertHarvey You're right. It's like using a goto in C#. Needed a bit of a wake-up there.
    – Joe
    Commented Oct 6, 2014 at 18:55
  • 3
    By extension, do you ever see a newspaper article with every other word turned into a gray blob? Some posters just can't seem to stay away from that darned backtick. Commented Oct 6, 2014 at 18:56
  • @BenjaminGruenbaum that would be a good analogy if not for the fact that apparently people do that, a lot. Actually, I just stumbled upon an example in a Java project today where a method doing import validation just contained 50 commented-out lines followed by a return null. I've seen worse in old C/C++ codebases though, e.g. functions of 3k lines that contain a huge nested if statement with multiple branches, and suddenly there's 500 lines commented out in the middle of it. Just like strike-through in answers, it makes the code a total mess.
    – l4mpi
    Commented Oct 6, 2014 at 19:28
  • 1
    @l4mpi don't people know they have source control for that? (The revision history in our case) Commented Oct 6, 2014 at 19:30
  • @BenjaminGruenbaum well, to be fair, the C/C++ project actually predates CVS and I don't have any idea what they initially used (I believe it was RCS because I remember a project manager mentioning how cumbersome it was to deal with locked files back then). Still no excuse to not clean that up once the project was migrated to CVS and then SVN...
    – l4mpi
    Commented Oct 6, 2014 at 19:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .