Slashdot Mirror


What Are the Unwritten Rules of Deleting Code?

Press2ToContinue writes "I came across this page that asks the question, 'what are the unwritten rules of deleting code?' It made me realize that I have seen no references to generally-accepted best-practice documents regarding code modification, deletion, or rewrites. I would imagine Slashdot's have come across them if they exist. The answers may be somewhat language-dependent, but what best practices do Slashdot's use when they modify production code?"

384 comments

  1. How can ... by Anonymous Coward · · Score: 0

    one unwrite that has which been deleted?

    1. Re:How can ... by ChunderDownunder · · Score: 5, Informative

      version control.

    2. Re:How can ... by hobarrera · · Score: 5, Insightful

      Indeed, version control is the only real solution.
      We use git at work, and some coworkers insist on "commenting out" code that's no longer needed. I insist that we should delete it. Should we ever need it again, we have version control; and with proper commit messages, old code is easier to find too.

    3. Re:How can ... by SerpentMage · · Score: 5, Insightful

      No I feel you should comment it out for one version, or one iteration.

      The problem with deleting code is that you lose functionality and information. Yes yes we have this ideal world where unit tests will ensure that the code only does what it is supposed to. Be that as it may, there is a reason...

      Code that needs to be completely rewritten is crap code. We can argue how it came to be, but the reality is that every developer for one reason or another has created crap code. It is unavoidable. Crap code is code that does many things, but quite a bit of it incorrectly. It also is hard to get a grip on because of its complexity. For if it was easy to understand and easy to fix it would not require a rewrite, no?

      Thus when you rewrite you are trying to simplify, and restructure. And because you don't have a handle of the original code you are going to introduce bugs in the new code. These bugs are new cases that you have not thought about and thus need thinking about. They are not critical bugs since the rewritten code is easy to understand and easy to fix. BUT these bugs need to be cross referenced with the original code. You need to see if these bugs are bugs, or actually the correct answer. Sometimes I was working on code and thought, "crap, the new code is right even though I thought this was a bug."

      If you delete, and need to check it with version control you are adding time, effort and complexity of actions. And then instead of going back to do a cross reference you are going to introduce new bugs that can grow into weeds and cause this cycle of rewriting again.

      I have found that often when I rewrite I learn new facets of my code and figure out the critical bugs. It is then I decide to stop the rewrite, and integrate the new code into the old code and fix things up. For the I see in the rewrite that the new rewritten code is going to introduce quite a bit of new code that is going to mean retesting, and assurance that things all work. And maybe this new rewritten code will not be better after all. Deleting the old code means me merging the refactored code, with the old code introducing even more complexity.

      Commenting out is ugly, but it has made it easier to experimenting in a short order of time without causing version control havoc.

      --

      "You can't make a race horse of a pig"
      "No," said Samuel, "but you can make very fast pig"
    4. Re:How can ... by bfandreas · · Score: 4, Insightful

      That's what I tell my team time and again. Do NOT simply use the IDE to comment code out. Delete it!
      If the code was replaced due to a change then the old one wouldn't work anymore anyway. If the old code was too clever(mostly too kludgy and not comprehensible) then do away with it. If the replacement causes any issues then use diff to find out what was changed.

      I'm quite brutal when it comes to purging stuff like that. And I have been known to be rather sarcastic when I find stuff that isn't covered via unit tests. But that is an entirely different matter.

      Maintaining code is hardly rocket surgery but normal housekeeping. There comes a time when the old pizza boxes have to go. Ideally before the roaches move in.

      --
      20 minutes into the future
    5. Re:How can ... by Alain+Williams · · Score: 2, Interesting

      Comments.

      Leave a comment saying something like: Version XX removed code to do YY because ZZ. The important things to comment are not what the code is doing (although that is useful) but the reasons for doing things and even more importantly the reasons for NOT doing things (eg: tried it but it was too slow).

      Comments are an apparently obscure feature of every programming language. I say obscure as most of the code that I see uses it rarely except for a copyright block.

    6. Re:How can ... by Decameron81 · · Score: 4, Insightful

      If rewrites are too complex you should split them up in phases. This is something few developers do, and something that can help you to test that the replacement code that you write does indeed what it's supposed to do. Between phases, testing is necessary - the more you can afford to test the new code, the less bugs you'll find later.

      As a general rule, leaving commented code into commits that you make to the main repository is a bad practice. The general idea is that if you do things right, by the time you commit the code you should be pretty confident it does what it's supposed to do - and I might add that this is the main reason why I think rewrites are NOT for any developer. Attention to detail and thorough testing are a must.

      When you commit commented code, you confuse other developers and add nothing of value to them. In most cases where I've seen devs do this, it's mainly because they are afraid they might need to roll back due to a lack of testing on their side.

      And as a last note: version control is there to offer roll-back support, comments are not. It's about using the right tool for each job.

      --
      diegoT
    7. Re:How can ... by Anonymous Coward · · Score: 0

      For those of us involved in programming machinery - rather than moving data around - a more organized approach is required. After all we don't want our machinery to do unintended stuff.

      See the "management of change process".
      Instrument Society of America has paper at the following link discussing the issue.
      http://www.isa.org/FileStore/Intech/WhitePaper/5450_White_Paper_Change_and_Configuration_Management_EN_Final.pdf

    8. Re:How can ... by Anonymous Coward · · Score: 0, Funny

      i never delete code even with version control, i just comment it out so that others can easily see what i removed with a comment as to why.

    9. Re:How can ... by VortexCortex · · Score: 4, Informative

      If you delete, and need to check it with version control you are adding time, effort and complexity of actions. And then instead of going back to do a cross reference you are going to introduce new bugs that can grow into weeds and cause this cycle of rewriting again.

      Spoken as a fool who doesn't use Git. Seriously, get a grip man. Version control works. I use commits as my "save" feature, I branch a codebase 2 or three times per day. I keep merges (mostly) sequential. Here's how I switch back and forth between two different branches right in the same source directory, so that I can test old "deleted" code vs the new re-write:

      $ checkout old-version-name
      Now I can make an out of source build of the old version... Then make a new branch in the same source directory.
      $ checkout -b new-version-name
      Now I can make an out of source bulid of the new version... make some changes, and then save them.
      $ git add . && git commit -m "Frobbed foo to make bar comply with baz"
      Need to make a change in the old version, or look at some code? $ checkout old-version-name

      It's better than SVN or Mercurial because you don't have to manage a bunch of folders of different branches, the files change automagically when you switch between your local branches. My IDE alerts me if the file's I'm about to edit were changed out from under it and need to be reloaded, so if the files need reloading then that's what I do. I use the diff viewer if I need to reference the old code while editing the new, or make another clone of my working repository with the old branch if I'll be doing that a lot. Seriously, you need to learn about distributed version control -- I don't need to worry about not committing something that's not perfect yet for everyone to see, I just commit it locally, and rebase all the ugly changes so only pretty gets seen in public -- all these commits and branches are on my local machine, so I can actually USE the version control rather than be its slave.

      Oh what's that? You use CVS or SVN and so you don't have a choice? BULLSHIT. Init a Git repo within the SVN checkout. Set git to ignore .svn folders and SVN to ignore .git. Make a git branch for "master" be the SVN branch you submit to the centralized repository, then you can branch your heart out and clone like there's no tomorrow, and merge into master, then make an SVN commit when you've got shit sorted. Accept that you've been a moron about version control all your life, and actually learn to use it. The Truth Shall Set You Free!

    10. Re:How can ... by ixnaay · · Score: 5, Insightful

      I need a moderation option for 'good points, but excessive dickishness' Anyways, I do pretty much exactly the same as you do; although in the firmware world.

    11. Re:How can ... by spongman · · Score: 2

      You can switch branches in SVN just fine. It'll even merge local changes between branches for you without having to stash/pop.

    12. Re:How can ... by Anonymous Coward · · Score: 4, Insightful

      If rewrites are too complex you should split them up in phases.

      Yep. In the VCS this you can easily do this using branches, doing all your development and testing outside of the trunk and then merging in a single commit back into the trunk.

      The general idea is that if you do things right, by the time you commit the code you should be pretty confident it does what it's supposed to do

      Not (necessarily) with branches. You can commit early and often since you're not changing the trunk. That means your commit log becomes a great timeline of the changes being made, you can almost always find older revisions of code to revert to and if anything goes wrong on your development platform you have a recent backup, which is always a good thing. If a commit is faulty then you can either correct or revert, but since no-one else is using your branch yet your faulty commit doesn't matter.

      And as a last note: version control is there to offer roll-back support, comments are not. It's about using the right tool for each job.

      Yep. In my view VCS is to provide rollback/backup/history. Comments are to explain actions being done to make code easier to read/follow, and in complex sections of code to explain the functionality to make them more intelligible (as an example to explain an algorithm being used, perhaps along with pseudocode for more complex ones). Comments should let you completely understand a program if you only have the single checkout, but don't need to give you any history.

    13. Re:How can ... by ojak · · Score: 1

      version control.

      In my experience, rewrites generally occur due to architectural changes or limitations, while refactors generally occur to improve code.

      So version control is extremely helpful for refactors, but not really a solution in itself for rewrites.

    14. Re:How can ... by Anonymous Coward · · Score: 3, Insightful

      If you delete, and need to check it with version control you are adding time, effort and complexity of actions. And then instead of going back to do a cross reference you are going to introduce new bugs that can grow into weeds and cause this cycle of rewriting again.

      Spoken as a fool who doesn't use Git. Seriously, get a grip man. Version control works. I use commits as my "save" feature, I branch a codebase 2 or three times per day. I keep merges (mostly) sequential. Here's how I switch back and forth between two different branches right in the same source directory, so that I can test old "deleted" code vs the new re-write:

      $ checkout old-version-name

      Now I can make an out of source build of the old version... Then make a new branch in the same source directory.

      $ checkout -b new-version-name

      Now I can make an out of source bulid of the new version... make some changes, and then save them.

      $ git add . && git commit -m "Frobbed foo to make bar comply with baz"

      Need to make a change in the old version, or look at some code?
      $ checkout old-version-name

      It's better than SVN or Mercurial because you don't have to manage a bunch of folders of different branches, the files change automagically when you switch between your local branches. My IDE alerts me if the file's I'm about to edit were changed out from under it and need to be reloaded, so if the files need reloading then that's what I do. I use the diff viewer if I need to reference the old code while editing the new, or make another clone of my working repository with the old branch if I'll be doing that a lot. Seriously, you need to learn about distributed version control -- I don't need to worry about not committing something that's not perfect yet for everyone to see, I just commit it locally, and rebase all the ugly changes so only pretty gets seen in public -- all these commits and branches are on my local machine, so I can actually USE the version control rather than be its slave.

      Oh what's that? You use CVS or SVN and so you don't have a choice? BULLSHIT. Init a Git repo within the SVN checkout. Set git to ignore .svn folders and SVN to ignore .git. Make a git branch for "master" be the SVN branch you submit to the centralized repository, then you can branch your heart out and clone like there's no tomorrow, and merge into master, then make an SVN commit when you've got shit sorted. Accept that you've been a moron about version control all your life, and actually learn to use it. The Truth Shall Set You Free!

      Spoken as a COMPLETE fool independent of version control.

      In other words, an out-of-control fool.

      Out of all the code you're working on, HOW WOULD YOU KNOW THERE'S DELETED INFORMATION IN A PREVIOUS VERSION OF ONE OF THE MANY FILES?

      You can't know that unless there's something there to tell you. And you're NEVER going to spend much time looking into a comment like /* deleted old processing and rewrote. 2009/11/4, A. Programmer */

      Yeah, you're going to dig through old versions of the source just to see what happened?

      No the fuck you're not.

    15. Re:How can ... by Lumpy · · Score: 5, Insightful

      "Code that needs to be completely rewritten is crap code. We can argue how it came to be, but the reality is that every developer for one reason or another has created crap code. It is unavoidable."

      I have found this to be the case for all code that comes out of TI for their MSP430 embedded processors. They use a convoluted system for their code that only a nutjob would love. I have thrown out their drivers for interfaces and rewrote them by hand just to avoid their crap. You DO NOT declare a function for your device driver in the .h file of another driver. WTF is wrong with their programmers?

      --
      Do not look at laser with remaining good eye.
    16. Re:How can ... by Kookus · · Score: 1

      I see no difference between Version control or commenting things out from a regression identification standpoint. The code isn't written correctly to do what you want.
      Having commented code everywhere just clutters things up and my CDO (it's just like ocd, but in alphabetical order just the way it should be) kicks in.

      So yeah, version control. There's a reason for it.

    17. Re: How can ... by ayahner · · Score: 0

      Answers like this scare me. There's no reason to comment instead of delete code if you have source control. Diff "previous version" works better than any comment. Can't believe anyone considers commenting out for one iteration hasn't been slapped by even the most intermediate Dev on their team.

    18. Re: How can ... by minogully · · Score: 2, Interesting

      A colleague of mine comments everything and deletes nothing despite the fact that we use version control. This leaves the actual non-commented code difficult to read and understand. Also, there have been times I may need to uncomment the code to use it again, but it takes too long to readapt it to work with the surrounding code that has evolved since the commenting, let along to understand exactly what's going on to make sure there aren't bugs. For me, I think deleting commented code should be based on the following algorithm: x = the amount of time to understand and/or adapt commented code for reintroduction y = the amount of time to rewrite the same piece of code if (x > y) { Delete the code } else { Leave it }

    19. Re:How can ... by turbidostato · · Score: 2

      "Comments.
      Leave a comment saying something like: Version XX removed code to do YY because ZZ."

      Truly. You absolutly need to comment that... in the commit message.

    20. Re:How can ... by Decameron81 · · Score: 1

      Not (necessarily) with branches.

      You're right on this. When I wrote that part of the comment I was thinking about publishing (committing, merging, puslishing, etc) changes to a public / shared / main branch in the repository. The idea being: don't break a branch that was not specifically created for your change.

      --
      diegoT
    21. Re:How can ... by Alain+Williams · · Score: 3, Insightful

      Sometimes you need to leave a line like that in the code - else some programmer in 5 years time may attempt to put some more code in that does the same thing; being completely unaware of why that was taken out previously.

    22. Re:How can ... by someones · · Score: 1

      thats what git is for.
      branches are cheap - use them ;)

    23. Re:How can ... by sarysa · · Score: 2

      As a general rule, leaving commented code into commits that you make to the main repository is a bad practice. The general idea is that if you do things right, by the time you commit the code you should be pretty confident it does what it's supposed to do - and I might add that this is the main reason why I think rewrites are NOT for any developer.

      This is great in theory, but often it might be someone else looking through those lines of code again, and without the direct reference to what needed to be changed before, the new developer may reinsert the bad code for one reason or another.
      Another case is when a feature is put in, but then the producer or whoever changes their mind before release. It's easier for the same developer to search through all the code for snippets they remember than it is to hunt through VCS, because you can't do a "find all files" on deleted code.

      There are many, many other cases for comment over immediate deletion, and I do prune my own comments once I feel confident with the change. That said, it's a bit arrogant to assume that your modifications are going to be perfect, even if you do a decent job of testing it yourself.

      I guess it's worth noting that where I work, there are usually only one or two people working on code at any given time, so commits are more focused toward backup than perfection. Your environment may vary.

      --
      Charisma is the measure of someone's ability to lie with a straight face.
    24. Re:How can ... by AlecC · · Score: 2

      If you delete, and need to check it with version control you are adding time, effort and complexity of actions. And then instead of going back to do a cross reference you are going to introduce new bugs that can grow into weeds and cause this cycle of rewriting again.

      The opposite of true for me. In my IDE( (Eclipse) is a single select from a drop-down menu for me to get a side-by-side comparison of new and previous, with new editable and old copyable. If I leave commented out old code, it is a scroll-up/scroll-down to compare new and old, which is much harder.

      You need tools for the job. Version control is part of it, as has already been mentioned, and version control aware editors another part of it.

      --
      Consciousness is an illusion caused by an excess of self consciousness.
    25. Re:How can ... by BrokenHalo · · Score: 2

      You need tools for the job.

      Trouble is, we have too many "tools" doing the job.

    26. Re:How can ... by rtfa-troll · · Score: 1

      Spoken as a COMPLETE fool independent of version control.

      In other words, an out-of-control fool.

      Out of all the code you're working on, HOW WOULD YOU KNOW THERE'S DELETED INFORMATION IN A PREVIOUS VERSION OF ONE OF THE MANY FILES?

      ...

      There are two scenarios that I can see here

      • A) the code was deleted correctly; it didn't cause a bug.
      • B) the code was deleted incorrectly; it did cause a bug.

      In case B, I will know the code was deleted by comparing first version with the bug with the last version without the bug. This seems trivial.

      In case A, the code was adding no functionality whatsoever to the program. I'm trying to work out why you would want to look up some code which was so useless that was in your program without adding anything? Wouldn't it be better to spend your time looking at random code samples on the internet, let alone using a Google search to see if there's a library related to your problem?

      --
      =~ s,(.*),<sarcasm>$1</sarcasm>,g if any_point_you_wish();
    27. Re:How can ... by tibit · · Score: 2

      I use SVN and Mercurial, but I'm much similar in my heavy dependence on version control. That's what it's for. I often have branches that live for a couple of hours just to try things out. If I ever need to come back to it, it's all in the repository -- no need for me to keep code elsewhere, possibly to be lost -- the code isn't cheap, even if it's a "throwaway" experiment. I tend to do many small commits, each of a self contained single-purpose action done to the code -- exactly as if it were a save feature. I had one 24h session where I made ~60 commits. I also use version control for electronic/industrial automation designs, and there, with small documentation revisions, I sometimes commit every 10 minutes. I can't understand why anyone would think it's too much work. It takes a couple of seconds, and documents your progress as long as you are serious about commit messages (like you well should be!).

      I don't particularly mind having separate working copies for things. Yeah, the git way may be more convenient, but these days checking out a 100 megs of stuff takes a few seconds anyway. Even on a virtual machine.

      --
      A successful API design takes a mixture of software design and pedagogy.
    28. Re:How can ... by defaria · · Score: 1

      That's completely asinine! Leave commented code because the code you write to replace it will be shit. Well maybe the code you write to replace it will be shit but not the code that I write to replace it. Besides we're not talking about the code that remains - we're talking about code that's been deleted. Often that code is shit and should go - period.

    29. Re:How can ... by BrokenHalo · · Score: 1

      In my first programming job, several of my more thankless tasks were fixing up code where the source had been (for one reason or another) lost. Back in the 1970s, this was not uncommon. The upside of this was that patching binaries directly was (and, of course still is) a challenge, and a nice change from the tedium of COBOL.

      Of course, in those days patches were usually submitted via cards punched on 029 door-stops, and version control was handled with a device generally known as a pencil. This lead to an approach where the fastest means to obtain a usable code was the best, and documentation didn't really come into it unless the programmer was not up to scratch.

    30. Re:How can ... by tibit · · Score: 2

      Yes, one can and should dig through old versions of the source. Your employer paid for it, you might as well use it. Like, um, duh!

      Similarly, there are those great things called GUI interfaces to version control. Heck, some even have with fancy graphs that show what files were modified and how -- including, incredibly enough, the aggregate counts of inserted, modified and removed source lines. Who'd have thought of that! Never mind the branch/merge graphs, etc.

      And, of course, viewing the diffs of larger commits is just so damn hard, right?

      The parent post is some bumbling idiocy, it seems.

      --
      A successful API design takes a mixture of software design and pedagogy.
    31. Re:How can ... by tibit · · Score: 1

      What kind of a nutjob is not at least familiar-in-the-passing with the project's history? I mean, fuck, suppose I'm an employer, I paid people to use version control, not NOT to use it. Using it doesn't mean merely committing things. First people are all "learn your history hurr durr", then they go to work and promptly forget it. What's wrong with people? Sigh :(

      --
      A successful API design takes a mixture of software design and pedagogy.
    32. Re:How can ... by DragonWriter · · Score: 2

      No I feel you should comment it out for one version, or one iteration.

      But that provides -- literally -- no value.

      The problem with deleting code is that you lose functionality and information.

      You lose exactly the same functionality as you do when commenting it out, and you lose no information at all if you are using version control, so neither of these concerns is a valid reason to prefer commenting-out over deleting.

      Yes yes we have this ideal world where unit tests will ensure that the code only does what it is supposed to.

      Unit tests aren't relevant here. The relevance is that deleting code from source files doesn't delete it from version control history, so if for some reason you need to recover the code, its still there.

      Code that needs to be completely rewritten is crap code.

      Not necessarily. "There is a better way to do it" doesn't mean the code is crap code, but sometimes the better way requires a complete rewrite. And, of course, deleting code doesn't mean rewriting code. Sometimes, requirements have changed such that previously-required functionality is no longer required, and you aren't "rewriting" the code that provides that functionality, you are simply removing it.

      Crap code is code that does many things, but quite a bit of it incorrectly.

      Again, no. Even code that needs rewritten because it is of exceptionally poor quality can be of poor quality for reasons other than mixing concerns.

      It also is hard to get a grip on because of its complexity.

      That may be true of some crap code, but even where the code is hard to get a grip on because of its complexity, it doesn't mean the requirements are (even if they were for the author of the crap code, which may just have been because the requirements were unclearly or incorrectly specified at the time the original code was written, and they may be clearly specified now.)

      Thus when you rewrite you are trying to simplify, and restructure.

      Possibly.

      And because you don't have a handle of the original code you are going to introduce bugs in the new code.

      Having a handle on the old code isn't relevant to introducing bugs. Having a handle on the current requirements is, and old code that is "crap code" that "does quite a bit ... incorrectly" is not likely to be the best resource in understanding those requirements.

      These bugs are new cases that you have not thought about and thus need thinking about. They are not critical bugs since the rewritten code is easy to understand and easy to fix. BUT these bugs need to be cross referenced with the original code. You need to see if these bugs are bugs, or actually the correct answer.

      The crap code that does things wrong isn't going to tell you if things are bugs or the correct answer, the requirements will tell you that. The crap code is, at most, going to tell you if the bugs were there before (of course, you can do the same thing by attempting to reproduce the bugs on the old build, and, in fact, if the problem is, as you suggest, that the old code is hard to understand -- and even if it is not -- the best way to tell if the bug is introduced with the code change or consistent with the prior behavior is to test with the old build, since that's a direct confirmation of the behavior, rather than what it appears from the code that the behavior would be.)

    33. Re: How can ... by pixelpusher220 · · Score: 1

      When you switch version control software...you often lose your history and ability to see what was done before. Doesn't mean leave a million lines commented, but some here and there is reasonable.

      --
      People in cars cause accidents....accidents in cars cause people :-D
    34. Re:How can ... by DragonWriter · · Score: 1

      Sometimes you need to leave a line like that in the code - else some programmer in 5 years time may attempt to put some more code in that does the same thing; being completely unaware of why that was taken out previously.

      If the final code has something that is likely to look like a code smell to someone unfamiliar with why it is that way but which has a good reason -- whether as a result of deleting code or not -- it may be valuable to put a comment explaining the reasoning so that someone coming to the code has the value of whatever process got to the end result.

      But that's not so much a comment about deleting the code (or adding, or whatever change made it the way it is -- and heck, it could be even the first version of the code, because the original programmer might have realized the right way), which is the process of how it got to be the way it is, as it is a comment about the current logic of the implementation.

    35. Re:How can ... by swillden · · Score: 4, Funny

      You can switch branches in SVN just fine.

      And as a bonus you'll have time to go get a cup of coffee!

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    36. Re:How can ... by Anonymous Coward · · Score: 0

      Sorry but the GP has a really good point and if anyone needs to be moderated down it's the amateur he's replying to that is posing as an authority figure on the subject. I'm surprised at how many poor coders there are in this whole topic that think commenting out code is a good thing.

    37. Re:How can ... by efalk · · Score: 1

      No I feel you should comment it out for one version, or one iteration.

      This is exactly what I do. Sometimes I leave it for a couple of versions, but basically you want it to still be there long enough to be sure that deleting it was the right thing, then get rid of it to clean up your code. Leave a good comment in the version history and you're done.

    38. Re:How can ... by pmarinus · · Score: 1

      I agree with SerpentMage that "bad code" may in fact be accomplishing something, and that unfortunately the badness may make it difficult to understand. I also agree that if the code was put in place to handle some unusual circumstance, it probably wasn't causing unit tests to fail. (A good programmer would probably add the edge case to the unit tests.) Before deleting (or commenting out) code it is important to try and understand it, and to incorporate that understanding into your comments. For example
      ## Deleted code that computed the maximum possible number of subcases as maxSubcases because ## no subsequent code references maxSubcases
      If you don't understand what the code is doing, you may want to ask someone with an historical understanding of the code. For example perhaps there used to be a memory problem that required a workaround, and you are dealing with code that is currently not needed.
      On the other hand, maybe a fix was put in to deal with a situation that could arise again, but because the situation was rare and the fix was buggy (no surprise since it was written by the author of the maxSubcases code) the code was removed, and updates were left for a day that never came.
      Running some kind of code checking software might also be useful, especially if you are using a language that doesn't require you to define variables in advance, but conveniently instantiates them for you.
      There could be code that says if (maxSubcasses > 15000) { ... which will never be triggered since maxSubcasses will always be 0, though maxSubcases won't. True story: many years ago I found an obscure FORTRAN bug in which an undeclared variable had a small positive value and worked successfully as an epsilon until a change in OS caused it to have the value 0, resulting in code failure.

    39. Re:How can ... by LF11 · · Score: 1

      What is it about git that spawns such unutterably foppish arrogance? It's like a hipster learning about hipsterism for the first time. *shudder*

      I say this as a daily user of git in professional and non-professional work. I love it and recommend it, but ... seriously?

    40. Re:How can ... by RabidReindeer · · Score: 2

      thats what git is for.
      branches are cheap - use them ;)

      Merging branches, on the other hand, can be a royal pain.

    41. Re:How can ... by HeckRuler · · Score: 2

      Well that took a while. Seriously, aren't there coders here who can cut through bullshit? Code modification, which includes deleting swaths of useless code and putting in something simpler, is called "refactoring". And there's been a shit-ton written about it.

      The refactor vs rewrite debate is likewise ancient. See: Mozilla.

      These are not unwritten rules. They're just things the author is ignorant of.

    42. Re:How can ... by RabidReindeer · · Score: 1

      Yes, one can and should dig through old versions of the source. Your employer paid for it, you might as well use it. Like, um, duh!

      My employer told me in no uncertain terms to "just Git 'R Dun!" He doesn't want me spending a lot of time looking at how things USED to work.

      If a chunk of dead code is still present and commented out, I can scan it and go on. Very few of those fancy tools can give me feedback that fast.

    43. Re:How can ... by ZombieBraintrust · · Score: 2

      Use a version control system that ties changes to a problem ticket. All versions and version comments for a paticular problem should show in the ticket. Nothing gets checked in unless tied to a approved ticket. Example systems: Clearcase with Clearquest, Subversion with TRAC.

    44. Re:How can ... by Synerg1y · · Score: 1

      Damn dude, not meaning to troll here, but sounds like you've written quite a bit of buggy code and thus benefit from your own approach of cross-referencing "bad" working code with yours... which I believe is legit, but when replacing large(er) chunks of code like that I find a notepad approach best, write down what the code is doing, and from what you can gather what the code's supposed to be doing (original rfp is priceless here, senior users are too) including the problem you're trying to solve by rewriting it (businesses benefit more from functional code than good code is the sad, but hard truth). So I wind up with a mini-rfp functionality requirements doc after which I delete the code in it's entirety (after source-control commit, making note of the commit # depending on size of team), and rewrite it again off my requirements doc, test it to make sure it meets requirements & send off for testing.

      It might seem similar, but the problem with merging good code with bad code on anything more than a quick patch is ime bad code tends to be very un-flexible so making a 5 minutes change takes 30 & because you've altered the structure of something held up on air, you've introduced possible bugs again that now you can't account for because it's not your code that's causing them, but your code is integrated into the bad code if that makes sense. So a moderate change can turn into 30 minutes into 4 hours of tracking down an anomaly.

    45. Re:How can ... by Synerg1y · · Score: 1

      so are local repositories, it's beyond me why anybody would commit non-working code to a non-local branch without getting it to work first, waste of a commit # if there ever was one. One cool thing I've seen people do is set these up with GIT & Tortoise on the side from say like TFS, or other non-locals, and commit the shit out of those for easy roll back (once you've done it a few times it's real easy) and only make relevant commits to the rest of the team.

    46. Re:How can ... by Spiridios · · Score: 1

      Spoken as a COMPLETE fool independent of version control.

      In other words, an out-of-control fool.

      Out of all the code you're working on, HOW WOULD YOU KNOW THERE'S DELETED INFORMATION IN A PREVIOUS VERSION OF ONE OF THE MANY FILES?

      You can't know that unless there's something there to tell you. And you're NEVER going to spend much time looking into a comment like /* deleted old processing and rewrote. 2009/11/4, A. Programmer */

      Yeah, you're going to dig through old versions of the source just to see what happened?

      No the fuck you're not.

      Wait, what?

      • Debug and find area of code causing issues.
      • Hit history/annotations/whatever on the file in question and find out when was the last time the problem area was worked on.
      • Figure out if that change is related to the bug.
      • Either fix or reassign bug

      If you are skipping step 2 you are causing a lot of extra work for yourself. If the bug was caused by Joe's last check-in, not only should Joe fix it because it's his fault, Joe's already familiar with that section of code and can probably fix it orders-of-magnitude times faster than you can. If not, Joe can help you fix it. If you caused the issue, you now have a diff of what was there before and what's there now. Step 2 is integral to team development when you can never be sure when/how files are changed. Maybe that's the difference? Commenters don't work on teams, so they only learn to use change control as backup?

    47. Re:How can ... by ewibble · · Score: 1

      But the rest of the time you have a bunch of useless comments sitting around that are not relevant, slowing down your real work so it is harder to get the job done.

      Removing needed old functionality once tested should be the exception not the rule. Coding for the exception is just silly, true going through version control is a bit more time consuming (not majorly so) but in some ways it is also better since you have runnable code, with the same structure and you can see exactly what is happening.

      "just Git 'R Dun!" which I think means just get it done, is a good way to dig yourself a nice big hole, you have to get it done right, surprisingly this turns out to be the fastest solution in most cases anyway since you don't have deal with the edge cases that so called quick solution created.

      The only time you should comment out a deletion is if the code is it is being temporarily removed.

    48. Re:How can ... by Anonymous Coward · · Score: 0

      Indeed, version control is the only real solution. We use git at work, and some coworkers insist on "commenting out" code that's no longer needed. I insist that we should delete it. Should we ever need it again, we have version control; and with proper commit messages, old code is easier to find too.

      "Proper commit messages" are something like...
      /* and */ inserted at various places

      Right?

    49. Re: How can ... by Anonymous Coward · · Score: 0

      Odd case. But I would favor keeping the old repo around read only in favor of commenting deleted code.
      Plus if your issue tracking is linked to source control as it should be, you'd need to.
      Issue tracking integration is essential though. Without it you'd have to comment every change and date each comment and keep every change on source comments with the I'd of the user... Etc

    50. Re:How can ... by tibit · · Score: 1

      The whole point is: it does not take a lot of time -- that's what the tools are for. If you're not supposed to look at old code, then, well, it should be deleted and you shouldn't look at it :)

      --
      A successful API design takes a mixture of software design and pedagogy.
    51. Re: How can ... by pixelpusher220 · · Score: 1

      I would favor keeping the old repo around read only

      The bean counters sadly wouldn't favor such unnecessary expense. And legal won't let you do it...

      I understand your point but reality doesn't always nicely fit what would work best. That said, hopefully it is an odd case and you aren't switching source control vendors too often ;-)

      --
      People in cars cause accidents....accidents in cars cause people :-D
    52. Re:How can ... by RabidReindeer · · Score: 1

      "just Git 'R Dun!" which I think means just get it done, is a good way to dig yourself a nice big hole, you have to get it done right, surprisingly this turns out to be the fastest solution in most cases anyway since you don't have deal with the edge cases that so called quick solution created.

      Unfortunately, my reputation IS for doing things correctly and carefully. I was very specifically told that that was my problem and that I should be more like "Joe" who got stuff "done" faster because he didn't think things through or put in exception-handling logic. That it was, in fact "better" to reboot the server daily than to "waste time" making an app that cleaned up after itself. They were very big on "Done" in that particular shop.

      I used to always delete dead code immediately. I've backed off on that lately because occasionally it turns out that the cure was worse than the disease and it's good to have the previous-generation code available for immediate reference. Especially when I have the offending module in dead-tree form far from a differencing server. And I'm afraid that in any event, the version-compare tools available to me have a very definite latency - I can't just hover a mouse and have the changes immediately pop up in milliseconds. Instead I have to explicitly issue a set of secondary commands, wait for the differences to be generated and the UI components to initialize and scroll as needed. Not a LONG delay mind you, but long enough to discourage casual usage.

    53. Re:How can ... by sarysa · · Score: 1

      Why would I want that? Where I work, that would amount to an unnecessary layer of bureaucracy. (and would be hell because our codebase is multinational) Plus, I do a lot of original development, an only a moderate amount of maintenance and fixes.

      --
      Charisma is the measure of someone's ability to lie with a straight face.
    54. Re:How can ... by spongman · · Score: 1

      not necessary if you're branching 2 or 3 times a day and you're connected to your repro by something faster than carrier pidgeons.

    55. Re:How can ... by swillden · · Score: 1

      And if your code base is small.

      OTOH, if you have several million lines of code and you switch branches a dozen (or two dozen!) times per day... SVN is really painful.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    56. Re:How can ... by spongman · · Score: 1

      the cost of switching is relative to the size of the diff, not the size of the repository. if you're branching 2/3 times a day, then the diffs are small, and therefore, quick.

    57. Re:How can ... by turbidostato · · Score: 1

      "Sometimes you need to leave a line like that in the code"

      Wrong: you never will need to do that. The comment "Version XX removed code to do YY because ZZ" explains the history of that code and, as such, it belongs to the history-tracking tool. If you feel an explanation about why some code is in a particular way instead of another, go ahead and add a comment, but that's a completly different issue.

    58. Re:How can ... by leenks · · Score: 1

      Not neccessarily - the codebase can drastically change between releases, and if you are attempting to backport fixes to multiple releases it can be really painful. Not to mention you need a great connection to your SVN server (which for a large team also needs to be fairly beefy). Git makes this much more efficient, and it is far easier/faster to identify where regressions occurred, determine the ancestry of lines within files, etc.

      But anyway, SVN is relatively good. We should be bashing CVS and Clearcase!

    59. Re:How can ... by leenks · · Score: 1

      gitk the file?

    60. Re:How can ... by spongman · · Score: 1

      if you want to argue GIT vs SVN I'd stick to SVN's inability to properly track change ancestry through branch merges. that's the reason I quit SVN, not the performance. a beefy server and a GigE switch are next to free.

    61. Re:How can ... by leenks · · Score: 1

      They aren't free in most businesses though. It's better to make staff suffer on 100 (or even 10) mbit networks and Pentium 4 machines with 2GB RAM than to spend any money on hardware that may not make them any more productive. At least thats the mentality of the IT departments I've seen!

    62. Re:How can ... by spongman · · Score: 1

      Oh that's fine for me. I just hope at least some of those incompetent it departments are in campanies that I compete against. Every little bit helps.

    63. Re:How can ... by Anonymous Coward · · Score: 0

      NO NO NO NO.

      Delete it. If you need it back, it's in the vcs. PERIOD. Commenting it out only leads to confusion.

      And if you don't have a serious set of unit tests, acceptance tests and integration tests you're not anyone I'd hire as a developer.

    64. Re:How can ... by lsatenstein · · Score: 1

      Indeed, version control is the only real solution.
      We use git at work, and some coworkers insist on "commenting out" code that's no longer needed. I insist that we should delete it. Should we ever need it again, we have version control; and with proper commit messages, old code is easier to find too.

      ===
      I do the following. I take a copy of the code before doing the delete, along with a timestamp. I add a brief paragraph comment in the code to indicate where to find the code before the image. I add to my paragraph, when to delete the paragraph itself.
      When the 6 months, or 18 months lapses. I delete the paragraph and the code I set aside as a separate file months before.
      I do not like long descendency paths for subversion or git. If the new code is clean for 18 months, I do a sv removeal and then register it again.

      --
      Leslie Satenstein Montreal Quebec Canada
    65. Re:How can ... by DarwinSurvivor · · Score: 1

      I was very specifically told that that was my problem and that I should be more like "Joe" who got stuff "done" faster because he didn't think things through or put in exception-handling logic. That it was, in fact "better" to reboot the server daily than to "waste time" making an app that cleaned up after itself. They were very big on "Done" in that particular shop.

      I'm guessing that particular company sold the code to other companies and didn't actually use it themselves? That's the only (immoral) way I can see justifying such an attitude.

    66. Re:How can ... by RabidReindeer · · Score: 1

      I was very specifically told that that was my problem and that I should be more like "Joe" who got stuff "done" faster because he didn't think things through or put in exception-handling logic. That it was, in fact "better" to reboot the server daily than to "waste time" making an app that cleaned up after itself. They were very big on "Done" in that particular shop.

      I'm guessing that particular company sold the code to other companies and didn't actually use it themselves? That's the only (immoral) way I can see justifying such an attitude.

      Unfortunately, no. They are a bank. A rather large one.

    67. Re:How can ... by DarwinSurvivor · · Score: 1

      Ah, a bank. No need to explain further.

  2. The more..... by phantomfive · · Score: 5, Insightful

    The more you can delete, the better.

    --
    "First they came for the slanderers and i said nothing."
    1. Re:The more..... by rwven · · Score: 5, Informative

      Yeah, I have no qualms about deleting code. There are others I've seen who just comment out massive blocks of code and leave them there....for me to eventually find and delete myself, apparently. Version control is there for a purpose. If you need something back...it's there.

    2. Re:The more..... by wmac1 · · Score: 5, Insightful

      I comment the code and leave it there for at least one minor version. If things are all right, I'll remove them. The code is in source control anyway.

    3. Re:The more..... by paulatz · · Score: 1

      The more you can delete, the better.

      Starting from the Murphy's law on programming:
      Every non trivial program has at least one bug

      You can derive by rigorous analogy the Murphy's law on not-programming:
      Every non written code has exactly zero bugs

      --
      this post contain no useful information, no need to mod it down
    4. Re:The more..... by mwvdlee · · Score: 5, Insightful

      Why not just delete it right away? Commenting out code in version control just creates more changes.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    5. Re:The more..... by Marxdot · · Score: 5, Insightful

      "It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away" --Antoine de Saint Exupéry

      That is the only rule of deleting code; if you can take it away or do it more simply without causing Bad Things, do it.

    6. Re:The more..... by Anonymous Coward · · Score: 0

      If a non-trivial program has at least one bug, we can prove by induction it has infinite bugs.

    7. Re:The more..... by Anonymous Coward · · Score: 5, Insightful

      If everyone uses the system "comment out first, remove after it has shown to work", seeing commented out code means that the code is still being reviewed. That might be valuable information.

    8. Re:The more..... by Pieroxy · · Score: 5, Interesting

      Once it's not in the file anymore it's out of your attention span. Leaving the code there for a revision or two allow anyone looking into the file to be instantly aware that something has happened very recently, which is usually what the person is looking for.

      Depending on your language, putting a "TODO" marker allows for easy and quick cleanup afterwards.

    9. Re:The more..... by beelsebob · · Score: 1

      How so? A non-trivial program can't have the bug removed without shrinking the non-trivial program. At some stage it will become trivial, so in fact you can prove it has finite bugs.

    10. Re:The more..... by hobarrera · · Score: 1

      Once it's not in the file anymore it's out of your attention span. Leaving the code there for a revision or two allow anyone looking into the file to be instantly aware that something has happened very recently, which is usually what the person is looking for.

      If this is your goal, then you should just practice code-review of every commit and that'll achieve the same goal.

    11. Re:The more..... by Whiteox · · Score: 3, Insightful

      I always keep in mind that the code I'm working on will be assembled, and the assembly is smaller and tighter with assembly oriented coding. So I do comment out working code and replace it with an alternate if I think it could be more efficient.

      --
      Don't be apathetic. Procrastinate!
    12. Re:The more..... by Anonymous Coward · · Score: 0

      I always keep in mind that the code I'm working on will be assembled, and the assembly is smaller and tighter with assembly oriented coding. So I do comment out working code and replace it with an alternate if I think it could be more efficient.

      What does that mean? Assembly code doesn't generate different executables depending on comments.

    13. Re:The more..... by Anonymous Coward · · Score: 1

      I that case, the best way for making your programs non-trivial is to write bugs intentionally.

    14. Re:The more..... by psmears · · Score: 4, Insightful

      If this is your goal, then you should just practice code-review of every commit and that'll achieve the same goal.

      Only if every single developer that might look at the code reviews every single line. That doesn't scale beyond a small team.

      In general it's best to delete unwanted code, but in some cases (e.g. where the code being changed is related to working a bug in a third-party's software, so it may not be possible to tell what the "right" code is apart from by experimentation) it can be useful to leave the deleted code around for a while to notify anyone fixing bugs in that area - provided a suitable comment explains why the code has been commented out. Leaving the code surrounded by "/*...*/", but with no explanation, is not helpful...

    15. Re:The more..... by tknd · · Score: 5, Insightful

      If you're going to do this, YOU HAD BETTER COMMENT ON WHY YOU COMMENTED IT OUT. Too often I come across a block of code that is just commented out. A quick glance means it had a purpose, but for what reason, I'm not sure because apparently it isn't needed anymore. So then I ask "why?" But there is no answer to this question. This is possibly the worst feeling of working with code--the idea that something was there, now is not, but they left it in for some reason and you don't know why.

      Now you're left with a couple scenarios:

      • The code caused a bug, but had some sort of purpose.
      • The code was replaced, and the new implementation is experimental which leads to
        • Exactly which lines of code did it replace?
      • It is dead code

      It is like walking into an offline factory line. Most bystanders will simply think "I had better not touch this or it could cause serious problems" so the only people in full control was the last shift of factory workers for that line. Meanwhile similar lines are still operating so you're not exactly sure why this particular production line was halted.

      Meanwhile if the code was in version control, I get a much clearer picture from diff on what exactly changed. If you just comment out a giant block and leave it there, check it in, then diff shows me that 2 lines had a comment added (in the case of block comments) or all the lines are commented out (modified, for single line comments). Now I have to diff again and skip to the version before that to get the picture I want, but now I may see other changes that may not be relevant.

      Either way, if you are commenting out code for the first two scenarios I listed, you need to think again about your version control system and manage it better. Experimental or untested stuff should be branched, not visible to other devs otherwise people make mistake it for production code. If I see commented out code blocks, I'm simply going to delete them myself because I can't read your mind and never will be able to.

    16. Re:The more..... by Anonymous Coward · · Score: 1

      Depending on your language, putting a "TODO" marker allows for easy and quick cleanup afterwards.

      Eating from dishes allows for easy and quick cleanup afterwards, too. Dirty dishes still pile up in house communities where there is much more visibility and much less distribution of responsibility than in a typical programming project.

      Which of 500 TODO comments in a project are you going to work on first? And who is going to pay you for changing something that worked before to something that works afterwards, for weeks on end?

      Don't delay work until the time of accounting for it is gone.

    17. Re:The more..... by Anonymous Coward · · Score: 5, Insightful

      I comment the code and leave it there for at least one minor version. If things are all right, I'll remove them. The code is in source control anyway.

      That's a fine sentiment for a one-man dev team with a relatively small codebase, where you know what you're doing and can keep a handle on things, but for larger teams, people who leave commented-out code in place are annoying for everyone else.

      As you said already, it's in source control anyway, so why bother leaving it there even for one version?

      The counter arguments are that it causes additional diffs and commits that are unnecessary, and it gets in the way for other developers -- it harms readability.

      And very often, despite best intentions, it ends up being left there for a lot longer than was needed. The original developer may not come back to that file for some time, and after just a few revisions, no-one is quite sure which bits of commented out code should be deleted and which should be left in place. Or maybe even maintained -- after all, if it's been left in place, that implies it might have to be re-instated, so if the code around it changes, the commented out code really ought to also be tweaked to keep it in line.

      No-one has time to stop and figure it out either; the temptation is always just to leave it well alone -- if it's been left there, then there must have been a reason, but it's not my problem, so I won't touch it. End result, a year or two down the line, and we have huge quantities of dead code floating around, which probably wouldn't work anyway even if it was re-instated, and someone has to waste time with an excersise to go through the codebase and remove it all.

      In your world of your own little projects, keeping dead code floating around may sound like a good idea, but in the real world it really isn't.

    18. Re:The more..... by Anonymous Coward · · Score: 1

      If everyone uses the system "comment out first, remove after it has shown to work", seeing commented out code means that the code is still being reviewed. That might be valuable information.

      In an ideal world that might be true, but in the real world, the commented out code ends up being left and forgotten and just accumulates as cruft until someone has to spend an unhappy Friday going through the codebase deleting it all.

    19. Re:The more..... by Anonymous Coward · · Score: 4, Informative

      He didn't say that. Alternate coding will give you a different assembly - eg capturing a keypress in a loop is different if you use a (basic) while-wend or a for-next. Comments are ignored in assembly anyway.

    20. Re:The more..... by Anonymous Coward · · Score: 0

      I always keep in mind that the code I'm working on will be assembled, and the assembly is smaller and tighter with assembly oriented coding. So I do comment out working code and replace it with an alternate if I think it could be more efficient.

      What does that mean? Assembly code doesn't generate different executables depending on comments.

      Whooosh

    21. Re:The more..... by Anonymous Coward · · Score: 1

      > remove after it has shown to work

      Seriously? Do you mean you don't have unit tests and quickie smoke screen tests for developers to run before they check in to prove their new code works and hasn't broken anything?

      Tell me where you work, I don't ever want to buy one of your products.

    22. Re:The more..... by Anne+Thwacks · · Score: 1

      I have not tried that, and it didn't work when I did try it!

      --
      Sent from my ASR33 using ASCII
    23. Re:The more..... by stifler9999 · · Score: 0

      I'm not a programmer, but this makes sense to me. Leave it for a release or two then delete it if it proves no problems removing it. It allows thoses who are looking for problems in the code to know what has been changed. I thought compilers removed commented code, so it shouldnt matter if the commented code is there for a while because the compiled exe would not be affected size wise.

    24. Re:The more..... by arth1 · · Score: 2

      The only case I see for leaving it in is if the code you took out is the obvious solution, but forever reason won't work in this case. Then it's a good thing to leave it in along with a comment stating why you use different code. That way, there's less risk that a future programmer refactoring code will replace it with the obvious solution.

      Anyhow, this whole article seems to have been copied from ars.technica. Don't sink this low, /. submitters - you are better than mere copyists.
      Or is this the direction the new owners want the site to go in? If so, expect it to die as users flee to more current sites - the ones posting the originals.

    25. Re:The more..... by Anonymous Coward · · Score: 0

      Assuming that no one deletes the diff files in the repository...

      Idiots do idiotic things.

      We just had this problem.

    26. Re:The more..... by gbjbaanb · · Score: 2

      deleting comments is hardly an onerous task.

      But if your team has such little concern for teamwork and code tidying as they go, then your problems run a little deeper than leaving comments present.

    27. Re:The more..... by Anonymous Coward · · Score: 0

      Version control is great... Unless they change it every 4-6 months, so you loose all history. That's my current situation...

    28. Re:The more..... by mooingyak · · Score: 4, Insightful

      > remove after it has shown to work

      Seriously? Do you mean you don't have unit tests and quickie smoke screen tests for developers to run before they check in to prove their new code works and hasn't broken anything?

      Tell me where you work, I don't ever want to buy one of your products.

      There's unit tests, and then of course the ultimate test: the production environment. If you set up perfect unit tests every single time, then you won't notice the difference between the two. If you're human like the rest of us, then every so often an assumption you hadn't even realized you'd been making will slip through your unit tests and you've got a production bug. But hey congrats if you've never promoted a bug to production before.

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    29. Re:The more..... by dkleinsc · · Score: 2

      Not the first example - Ken Thompson predates that with his "One of my most productive days was throwing away 1000 lines of code."

      --
      I am officially gone from /. Long live http://www.soylentnews.com/
    30. Re:The more..... by Kookus · · Score: 1

      Git help branch

    31. Re:The more..... by Anonymous Coward · · Score: 1

      I almost always delete, rather than comment out, but I actually just a few days ago commented out a decent chunk of code instead of deleting for what I think is a good example of, "when to do it."

      I was doing a code review and found a rather nice, clean, set of new code that mapped a large set (A) of attributes to a small set of attributes (B). The problem was, is we do not have great documentation on which of the attributes in set A are guaranteed to exist. We could set up lots and lots of endless meetings with external teams to identify this, or the code could be limited to a few known attributes. However, limiting to known attributes meant making assumptions like, "if something will never have both attr. 0 and attr. 1, so we can apply both and only the proper one will stick".

      This might break with a change upstream at some point, so I thought it was good to keep the "proper" solution (with a comment explaining what it is) in the source.

    32. Re:The more..... by ATMAvatar · · Score: 1

      I should hope the testing and code reviews you do prior to merging means the change was reviewed. By commenting it out, you are deleting the code as far as the compiler is concerned, but as far as your coworkers are concerned, it's still there to reduce readability.

      --
      "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
    33. Re:The more..... by Pieroxy · · Score: 1

      If your manager doesn't give you time for cleanup / refactoring you have another problem. I take pride in making so that my code doesn't generate a single Warning and doesn't have a single TODO I don't know why is there.

      When working on old code written by someone else I apply the same policy: I leave it with no TODO nor any Warning, unless called for.

      It's not very complicated really, and going through the TODO is something I do every quarter. Just because it bugs me that there are TODOs.

      It all depends on how you work and how you like things. And frankly speaking, some old code commented out doesn't clutter the file for long after the 3 required seconds are spent deleting it. Specifically if the dude commenting it out did put the date at which (s)he commented it out, it takes less than 3 seconds.

    34. Re:The more..... by Anonymous Coward · · Score: 0

      Very nice words.

      In general, with source code, when you have the opportunity try to simplify it, and when you have bugs fix them. The excess "grease" must go away because of two main reasons:

      1) Readability: Maintenance becomes a nightmare trying to understand what happens inside many lines of commented erased code.
      2) Security: Particularly with HTML or Javascript code, you can provide clues to bad people about what are you thinking when you fix your code, so they can find ways to break your products.

      Have two methods to learn from your actions:

      1) Version control software.
      2) Change log OUTSIDE your code.

      The second one can be used for others to understand better why your programs have their current shape instead of forcing you to try to understand every programming decision traveling through many layers of previous source code versions.

    35. Re:The more..... by CastrTroy · · Score: 1

      I guess one corollary of that is if you make your functions simple (trivial) enough, and treat each function as a separate program, then you can rid the system of bugs. Ok, in practice it won't work perfectly, but breaking you code into small trivial pieces can often help to reduce the number of bugs. Writing single functions that go on for hundreds or thousands of lines if often a way to get yourself in a lot of trouble.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    36. Re:The more..... by BVis · · Score: 2

      Tell me where you work

      Someplace that will only grudgingly give you enough time to write sloppy quick-and-dirty code. Try telling an accounting troll that you need another third as much time to make sure your code is covered. I believe that's commonly referred to as a "Career Limiting Event' as you soon get a reputation for padding your time estimates with activities that do not directly create value. ("Value" being defined as "something we can sell", not "good code". Most of the time those aren't the same thing.)

      And if you're thinking "That's not someplace I want to work or buy products from", plan on 1) permanent unemployment and 2) never buying anything again.

      --
      Never underestimate the power of stupid people in large groups.
    37. Re:The more..... by Maximum+Prophet · · Score: 1

      Version A has a bug, so the code is deleted and replaced with Version B.

      Version B also has a bug, and gets replaced with Version A.

      In an ideal world, before every change, someone would look at the previous versions. Leaving the commented code in helps prevent back and forth code fixes.

      --
      All ideas^H^H^H^H^Hprocesses in this post are Patent Pending. (as well as the process of patenting all postings)
    38. Re:The more..... by doug · · Score: 1

      Not really. If the code was in for 2 weeks before being found to have a corner case bug, a "look here first" indicator is not bad. Especially so if the person fixing the bug is not the same person who made the original change.

    39. Re:The more..... by Anonymous Coward · · Score: 0

      Come on now lets be honest, this is hardly ever the case. We all know it's just being lazy. Once code gets commented out it just sits there forgotten.

    40. Re:The more..... by Anonymous Coward · · Score: 0

      That's a fine sentiment for a one-man dev team with a relatively small codebase

      I would argue that not even then. We've all been lumped with the huge system that was originally designed by one person. You should always code under the assumption that one day someone else will need to take over.

    41. Re:The more..... by mark-t · · Score: 1

      Even better would be if programmers would actually test their own code before committing in the first place, and to keep their commits fine-grained so that it's easy to just revert only the necessary lines if/when bad code does make it into the vcs repository.

    42. Re:The more..... by tibit · · Score: 1

      Once it's not in the file anymore it's out of your attention span.

      I'd be careful with such proclamations. They make you less hireable, at least in my opinion. Someone paid for the code, coaxed the coders to use the version control, etc. Just because it's not in a file on a filesystem in your working copy means it's out of your attention span? What are you, a drooling teenager?

      --
      A successful API design takes a mixture of software design and pedagogy.
    43. Re:The more..... by swillden · · Score: 1

      Where I work, if you comment out code rather than deleting it, you won't get past the code review, and you can't submit until the reviewer has signed off.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    44. Re:The more..... by fatphil · · Score: 1

      The guy who does "just removing the code with one cut" rather than "commenting out the code, then later removing the commented out code" can happily take a third as much time and be more efficient, as he's only doing half the number of changes. 1.33 < 2

      --
      Also FatPhil on SoylentNews, id 863
    45. Re:The more..... by Pieroxy · · Score: 1

      Once it's not in the file anymore it's out of your attention span.

      I'd be careful with such proclamations. They make you less hireable, at least in my opinion.

      I'm not looking for a job, and whenever I am I do not disclose any of my online nicknames so I should be fine on that front.

      Someone paid for the code, coaxed the coders to use the version control, etc. Just because it's not in a file on a filesystem in your working copy means it's out of your attention span? What are you, a drooling teenager?

      Remember, you don't only code for you but for all the people that may in the future have to work with your code. And yes, in most cases that may include a drooling teenager. So if I decide to do something with my code it doesn't mean I feel it will be necessary for ME, but for the collective.

      Besides, having something in front of your eyes (such as commented out code) is more likely to draw attention than a commit message 34 commits ago. So yes, even for me, it's more likely to draw attention commented out in the file than burried in git.

    46. Re:The more..... by lilo_booter · · Score: 2

      Definitely agree with this. Commented out code can be a severe aggravation, and not just for source control - searches can also bring up false positives. Better to clean it out entirely at the earliest opportunity.

    47. Re:The more..... by BVis · · Score: 1

      I was referring to unit testing / smoke testing, not commenting vs. cutting code. So I guess I'm pretty OT.

      --
      Never underestimate the power of stupid people in large groups.
    48. Re:The more..... by Immerman · · Score: 1

      You did remember to actually do performance profiling on your executable first to see if the code you're optimizing will actually have any impact on runtime performance, right? Otherwise you've just wasted energy (both present and future) by replacing clear code with a more clever, difficult to maintain alternative. One of the great truisms of optimization is that even good programmers tend to be really bad at recognizing the actual performance bottlenecks in code.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    49. Re:The more..... by Anonymous Coward · · Score: 0

      There are many industries that will not accept your excuse for letting bugs in. If you are serious about writing good code, you would have unit tests, integration tests, regression, ops testing, qa environments, dedicated qa testers, and staging environments. Testing should not be an afterthought, it should be the majority of what a software developer does all day.

    50. Re:The more..... by fatphil · · Score: 1

      Dan Bernstein has that approach. IPC is cheap nowadays, security and bugs are expensive, so it's a sensible trade.

      --
      Also FatPhil on SoylentNews, id 863
    51. Re:The more..... by HyperQuantum · · Score: 1

      "It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away" --Antoine de Saint Exupéry

      This might just be the motto of the GNOME folks.

      --
      I am not really here right now.
    52. Re:The more..... by defcon-11 · · Score: 1

      Or maybe you shouldn't be commiting unreviewed code in the first place (at least the master/trunk branch)

    53. Re:The more..... by defcon-11 · · Score: 1

      If I was performing a reviewing code and saw a bunch of commented out code, I'd ask why the hell it was there and tell the perpetrator to remove it before committing.

    54. Re:The more..... by snemarch · · Score: 1

      There's unit tests, and then of course the ultimate test: the production environment. If you set up perfect unit tests every single time, then you won't notice the difference between the two. If you're human like the rest of us, then every so often an assumption you hadn't even realized you'd been making will slip through your unit tests and you've got a production bug.

      ...and if you've left the old code commented out, it's much faster to hotpatch the production servers by flipping some comments around, than doing a full rollback.

      /me ducks and covers.

      --
      Coffee-driven development.
    55. Re:The more..... by defcon-11 · · Score: 1

      How does leaving commented code help avoid bugs? If a bug was introduced into the code base, first thing an investigating developer usually does is look at the vcs's change log to see what changed, where the deletion will be obvious. Leaving it in the code doesn't make it any more discoverable, and there is a pretty good chance someone will forget to delete it.

    56. Re:The more..... by defcon-11 · · Score: 1

      Depending on your language, putting a "TODO" marker allows for easy and quick cleanup afterwards.

      Only if I am allowed to punch you in the face every time I see a TODO in the code from 3 years ago with a terse description that doesn't even match the current code. If it's something that needs to be done now, then do it. Otherwise, track the task as a ticket/store/defect, whatever method you use for tracking and prioritizing work, but please, please don't put a useless comment in the code.

    57. Re:The more..... by lingon · · Score: 1

      There's unit tests, and then of course the ultimate test: the production environment. If you set up perfect unit tests every single time, then you won't notice the difference between the two. If you're human like the rest of us, then every so often an assumption you hadn't even realized you'd been making will slip through your unit tests and you've got a production bug.

      ...and if you've left the old code commented out, it's much faster to hotpatch the production servers by flipping some comments around, than doing a full rollback.

      /me ducks and covers.

      If that is the case, your version control system sucks big time. It's that simple. Seriously, git revert oldhash takes about two seconds. One minute if you have a large merge conflict.

    58. Re:The more..... by lingon · · Score: 1

      You don't tell the accounting troll you're almost done and just developing unit tests and refactoring your code before checkin. You tell them it doesn't work yet (which is true, because you're not done until you've refactored and added the appropriate test cases).

    59. Re:The more..... by Anonymous Coward · · Score: 0

      Just be careful where you work. The last place I worked a guy went nuts at me for suggesting to delete an empty class that wasn't used (made as part of a default wizard) and insisted I document it instead (a comment to say it is empty but not to worry about it), when I shrugged and didn't do it right away he complained to my boss who started a performance management process. I took it to the CEO who said every developer there would agree not to delete an empty class but to document it instead. The last straw was later on when I had to rewrite a 20 year old installer and there was a mysterious creation and deletion of a file on a fileshare during the install that wasn't easy to do with the new installer - when I suggested that why not try without it if nobody knows why it was there they all panicked and beat me up again. Note I didn't actually do the alternative they just freaked out because I suggested it and it seemed crazy to them and they thought less of me because of it. I'm now happily away from there. My advice is to make sure that everyone agree's on coding standards, and be careful how you present alternative possibilities. The guy there who liked 'var' instead of explicit variable declarations got mysteriously moved onto another team.

    60. Re:The more..... by tibit · · Score: 1

      I think it's a weird workflow if something would be considered "buried" in a repository. The tools are there to make it manageable and visible. If things get "buried" in the repository, you're not using it effectively, I'd think.

      --
      A successful API design takes a mixture of software design and pedagogy.
    61. Re:The more..... by snemarch · · Score: 1

      ...and then you have to build the deployment packages, fire them off to the production servers, etc. Even with automation, that can take a while. Not everybody runs a PHP/ruby/whatever shop and have their git repos on their production servers ;p *duck and cover again*

      In case it wasn't obvious: this post and the previous one are extremely tongue-in-cheek. I don't really condone hax0ring code straight into the Gibson.

      --
      Coffee-driven development.
    62. Re:The more..... by c0lo · · Score: 1

      Why not just delete it right away? Commenting out code in version control just creates more changes.

      How long back in the history one need to go back to recover the deleted code? While retrieving a deleted block, how many and which other changes needs will also need to be reverted for getting the functionality in a consistent state ?

      Mind you: the above questions are valid no matter if you choose to delete a commented code or just to let it there still commented. What may disappear from view you carelessly choose to delete it: any immediately visible sign that there was a different code performing the job somehow differently.

      --
      Questions raise, answers kill. Raise questions to stay alive.
    63. Re:The more..... by Anonymous Coward · · Score: 0

      Sort of depends on both the version control, how good your team is at using it and the structure of the changes.

      Git makes it easy to get the old code back if you need it and easy to see that a change was made. Not all version control systems make it easy.

      The development team needs to be able and willing to use those features of git (or substitute your VCS) without fouling up the code.

      Then, too, a change that consists of getting rid of 10 blocks of code scattered across your codebase isn't so easy to recover without leaving out some bit. That also depends on how you use the version control and the granularity of checking in code. (Think how easy it is to segregate one particular fix scattered across those source files with one comment in your VCS. Think about how you might need to go back in and make another change at some later date, related to the same problem, because it took a while to find some subtle problem.)

      If its hard to recover the original, it may be easier to comment out bits and recover by uncommenting them. Sort of depends on your team's whole way of working.

      I don't think a simple answer works though deleting, when you can, does work.

      (Darn its hard to keep logged in not to mention being able to post something non-trivial without being told something isn't consistent.)

    64. Re:The more..... by Hobadee · · Score: 1

      rm -rf /

      Do I win?

      --
      ...Had this been an actual emergency, we would have fled in terror, and you would not have been informed.
    65. Re:The more..... by Anonymous Coward · · Score: 0

      But be sure to take good care of the deleted data. It might hunt you in your next project.
      That's why in Japan we have a special temple service for it :
      http://dagmar.lunarpages.com/~parasc2/articles/slips/fs_172.htm

    66. Re:The more..... by mattack2 · · Score: 1

      Seriously? Do you mean you don't have unit tests and quickie smoke screen tests for developers to run before they check in to prove their new code works and hasn't broken anything?

      Seriously? Do you mean you don't actually have huge third party developers that sometimes BREAK the rules, yet you have to support them?

      Testing that one tiny specific thing works in isolation is not the same thing from ensuring in the real world that all (ab)users of the APIs are doing the right thing too. Sometimes commented out code/breadcrumbs explain why something was done a certain way in the past, but was changed because of some other reason.

    67. Re:The more..... by mooingyak · · Score: 1

      I'm with you actually. I prefer deletion to commenting lines out myself. My complaint was with the anonymous poster who responded as if unit tests are some magic bullet that prevent every bug imaginable from seeing the light of day.

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    68. Re:The more..... by mooingyak · · Score: 1

      There are many industries that will not accept your excuse for letting bugs in. If you are serious about writing good code, you would have unit tests, integration tests, regression, ops testing, qa environments, dedicated qa testers, and staging environments. Testing should not be an afterthought, it should be the majority of what a software developer does all day.

      And there are also industries where a production bug doesn't mean someone dies or a plane crashes or a brokerage loses $200 million. If bugs have a significant potential for disaster, then sure, you set up all those environments. But that's not always the case, and sometimes your user base would rather have their reports a few hours late twice a year instead of paying for the hardware and support staff to keep all those environments functioning correctly.

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    69. Re:The more..... by mwvdlee · · Score: 1

      How long back in the history one need to go back to recover the deleted code? While retrieving a deleted block, how many and which other changes needs will also need to be reverted for getting the functionality in a consistent state ?

      Don't really know and don't really care. My IDE has Git support and makes this trivial and gives me an accurate record of all changes since the deletion. Deleted code will be equally inconsistant (atleast I sure as hell hope you didn't continue to make changes in commented code).

      Mind you: the above questions are valid no matter if you choose to delete a commented code or just to let it there still commented. What may disappear from view you carelessly choose to delete it: any immediately visible sign that there was a different code performing the job somehow differently.

      No. Commenting out code gives the false impression that something was happening there that is no longer happening. It is far more likely that whatever that code did is refactored, incompatible with the current data model or was plain bad code. All it does is confuse the reader into thinking the code is somehow significant to the current version whereas it was only significant to the point in version control whereafter it was removed.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    70. Re:The more..... by BVis · · Score: 1

      Do you think the accounting troll cares about that? If said troll finds out that you are in fact done writing the code and are refactoring and adding test cases, you can forget about getting any more time on that, and your time estimates will be cut by a proportional amount each time. And you'll get a reputation for padding your time estimates, since it doesn't really take you that long to write the code. Besides, we'll just release patches if we find problems.

      --
      Never underestimate the power of stupid people in large groups.
    71. Re:The more..... by kmoser · · Score: 1

      Add a keyword in the comment, e.g. "TOBEDELETED". Then write a script that goes through your source and deletes all comment blocks containing that keyword. Oh, and who cares if the script has bugs--you're using source control, right?

    72. Re:The more..... by Anonymous Coward · · Score: 0

      THIS

  3. Your VCS should manage this by symbolset · · Score: 2

    Delete away! It's not like legacy versions aren't available. Most code should be deleted. Almost all production code is bad.

    --
    Help stamp out iliturcy.
    1. Re:Your VCS should manage this by myurr · · Score: 5, Insightful

      Revision control is just one aspect. If you aren't the only person working on the code, or if there are other external dependencies such as you publish an API that others depend upon, then some form of automated testing will help ensure you haven't broken anything by deleting that code. Heck even if you are the sole developer then automated tests are still an incredibly good thingl.

      If you are deleting code within a larger project then try deprecating the code first. Flag it as deprecated in the documentation (you do have documentation don't you?) and put log messages in the code that warn whenever it is called. After a while you can be confident that it is unused (or only used in obscure rarely called functions) and you can delete with confidence.

      Revision control is your safety net, your last line of defence if you erroneously delete code that is in fact needed. It also allows you to always refer back to that code. Good commit messages will also help.

    2. Re:Your VCS should manage this by Anonymous Coward · · Score: 0

      The article is mislabeled. It's really about rewriting, not deleting.

    3. Re:Your VCS should manage this by angel'o'sphere · · Score: 1

      Most IDEs allow you to select the method/function with that code and display a call graph. So log messages are the most useless idea ...

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    4. Re:Your VCS should manage this by LordLucless · · Score: 3, Insightful

      Let me know how well that goes for you when your IDE tries to generate a call graph including third party applications that interface with yours via an HTTP API.

      --
      Just because you're paranoid doesn't mean there isn't an invisible demon about to eat your face
    5. Re:Your VCS should manage this by White+Flame · · Score: 1

      That's a useless assumption when dealing with dynamically loaded/dispatched code, or editing library code that will be pulled in by multiple projects. Logging always shows what's actually in use during a run.

      Besides, if you break the static call graph, the compiler will complain anyway. No need to graph.

    6. Re:Your VCS should manage this by Anonymous Coward · · Score: 0

      Or try languages like JavaScript or python. You don't even need any external dependencies in those languages. Your own code might do some dynamic runtime crap that no IDE in the world will tell you about. Heck that's even true with java, where the IDE can usually tell you everything. But start doing dynamic runtime evaluations and you are out of luck.

    7. Re:Your VCS should manage this by angel'o'sphere · · Score: 1

      or editing library code that will be pulled in by multiple projects.
      When you can not make sure the code is not used anymore then imho there is no reason to delete it.

      Besides, if you break the static call graph, the compiler will complain anyway. No need to graph.
      What is that supposed to mean? The compiler complains because a method/function is no longer called? That is new to me.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    8. Re:Your VCS should manage this by angel'o'sphere · · Score: 1

      That goes superb.

      There is no difference wether my function is called by another low level function or by an HTTP endpoint, or do you believe an external system can call my function "just so"?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    9. Re:Your VCS should manage this by Anonymous Coward · · Score: 0

      Which. Is. Why. I. Hate. Dynamic. Typing.

      Makes it really easy to hack code. Makes it really hard to not end up with errors being caught in production in obscure and overlooked corner cases which statically typed languages would have caught in compilation.

      Quantity vs. Quality.

    10. Re:Your VCS should manage this by uncqual · · Score: 1

      The problem usually isn't that the entire procedure is unused (that's fairly easy to catch). Usually it's that some chunk of the procedure "appears" to be unreachable because callers should no longer (or perhaps ever should have) invoke(d) the procedure with parameters and state that causes the code in question to be executed.

      --
      Why is there an "insightful" mod and why isn't it "-1"? If I wanted insight, I wouldn't be reading /.
    11. Re:Your VCS should manage this by Anonymous Coward · · Score: 0

      other external dependencies such as you publish an API

      You should be free to delete anything you like within your code, preserved in VCS as long as you maintain all required API functionality. If it means an actual change to the API then that then becomes a higher level design decision and the system designer (whether that be yourself, a higher up or your team) then needs to look at the impact of that.

      Many C libraries generally handle this by marking an interface deprecated (there's a flag you can set that gives compile-time warnings as a result). You maintain the functionality for some time (say a couple of years) then remove the function, by which time you've given plenty of people to move to the newer API.

    12. Re:Your VCS should manage this by Anne+Thwacks · · Score: 2
      I have news for you: some code is not actually written in c.

      Also some code's functionality is sufficiently complex that it is unclear what the functionality is. (eg depends on the external world in a complex manner).

      Some code works correctly despite/because of compiler/processor bugs, and changing the code in a manner that should not affect its behaviour, actually does, for undocumented, and possibly previously unknown, reasons.

      PS not everyone writes code for Windows.

      --
      Sent from my ASR33 using ASCII
    13. Re:Your VCS should manage this by Anonymous Coward · · Score: 0

      some code is not actually written in c.

      PS not everyone writes code for Windows.

      I like the part in his post where it says those two things.

    14. Re:Your VCS should manage this by Anonymous Coward · · Score: 0

      Compiled languages do work in that way, not just C.

      For distributed APIs (AJAX etc), I like Google's approach. Versioned APIs and maintain the functionality of old API interfaces for some time. Applications pick the version they know they work with. API changes can then be made without breaking old applications, for as long as that version of the API is made available. You can also monitor usage of versions from your HTTP server logs, so you'll know who is still using it and can use that to inform decisions when retiring older versions.

    15. Re:Your VCS should manage this by Charliemopps · · Score: 1

      Yes, we have huge swaths of production code that was written years, even decades ago... and we have no idea what it's for. It's hard to get a project approved that involves cleaning it up when there's no one inside the company pushing for it and it's benefit to the users is, at best, completely transparent. I'd love to go through there with an axe some weekend, but the potential that portions of it are still needed makes it a terrifying project to just do on my own.

    16. Re:Your VCS should manage this by UnderCoverPenguin · · Score: 1

      While your IDE can certainly see which functions are called by your RPC handler, unless client projects share their RPC external references with your IDE, it can't know which functions are actually used by any particular client project.

      --
      Don't try to out wierd me, three-eyes. I get stranger things than you, free with my breakfast cereal. --Zaphod Beeblebr
    17. Re:Your VCS should manage this by UnderCoverPenguin · · Score: 1

      More likely it would be the linker detecting that one or more symbols is unreferenced.

      The linker my team is using in our current projects has an option to log warnings about unreferenced symbols. We enable this because it provides an extra line of defense against coding errors - and documentation errors.

      --
      Don't try to out wierd me, three-eyes. I get stranger things than you, free with my breakfast cereal. --Zaphod Beeblebr
    18. Re:Your VCS should manage this by LordLucless · · Score: 1

      Because nothing says "dynamic typing" like Java. The sort of introspection that runs merry-hell with generating call graphs isn't a function of dynamically typed languages.

      --
      Just because you're paranoid doesn't mean there isn't an invisible demon about to eat your face
    19. Re:Your VCS should manage this by angel'o'sphere · · Score: 1

      Ah, thats a good hint. I don't work since ages with "linked" languages, but that is good to know and remember.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    20. Re:Your VCS should manage this by angel'o'sphere · · Score: 1

      Exactly my point, thee is an RPC handler, and if there is no trace of a call stack to the function/method in question down from that handler no external client is using it.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  4. Revertable by hism · · Score: 2

    what best practices do /.'s use when they modify production code?"

    Should be able to easily revertable

    1. Re:Revertable by gagol · · Score: 4, Interesting

      When in doubt, comment out and document. I also like to keep a commented (disabled by comments) generic version of a function if I have to work a heavily optimised version. For future generations, and keep sanity when code is revisited.

      --
      Tomorrow is another day...
    2. Re:Revertable by Anonymous Coward · · Score: 1

      When in doubt, sort it out!
      Commented out code has the potential for making ruin! If your not sure about something, don't push that uncertainly into someone elses hands.

    3. Re:Revertable by serviscope_minor · · Score: 2

      I try to keep an uncommented version.

      In debug mode, the optimized one will call the simple one and check the results are equal.

      Doesn't work easily in all cases if the function erforms mutation though.

      --
      SJW n. One who posts facts.
    4. Re:Revertable by Anonymous Coward · · Score: 0

      That works fine until you start changing the behavior of the optimized version. Like all other comments, if they're not actively maintained they're worse than useless - they're actively harmful.

    5. Re:Revertable by Just+Some+Guy · · Score: 1

      So now you have to keep two separate codebases in lockstep, with one documenting how the other should work. I think you're far better of thoroughly documenting why the optimized version does what it does and deleting the un-optimized original.

      --
      Dewey, what part of this looks like authorities should be involved?
    6. Re:Revertable by Anonymous Coward · · Score: 0

      NOT this. Oh god NOT THIS.
      You have a version control system! Use it!

      Commenting out code only makes diffs LESS readable. If any part of the change which you are committing needs explanation or historical notes: Put it in the commit message!

      Don't clutter the code with useless comments that only leave future coders to wonder "Why is this here? Was he testing out an alternative and forgot to remove it before checking in? How does it actually differ?"

      NEVER EVER commit commented-out code!

  5. Version Control Is Your Friend by Marillion · · Score: 4, Informative

    I really like git, but the key thing is to keep revision history. Deleted code is then never "deleted" it's just no longer cluttering up the screen. Of course it does mean you need to actually learn how to use a version control system beyond blind forward checkins.

    --
    This is a boring sig
    1. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 1

      version control is necessary, but if it isn't backed up regularly, it can be worse than worthless, offering a sense of security it may not provide. Offsite backups of your version control repository is critical. Or when the server room catches fire, all you'll have is whatever code was checked out at the time, if the workstations survive at all.

    2. Re:Version Control Is Your Friend by LordLucless · · Score: 3, Informative

      With modern distributed VCSs, like git, or mercurial, every clone is a repository. That's not to say backups aren't important, but if you've got your clone on your laptop, then you'll have lost nothing except what's been committed since the last time you pulled down the codebase.

      --
      Just because you're paranoid doesn't mean there isn't an invisible demon about to eat your face
    3. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 4, Insightful

      Version control is not your friend when you use it like this. It becomes your worst fucking enemy.

      Unless somehow your version control system somehow magically achieves the ability to imbue the knowledge of all the things that you tried and failed, and why they failed.

      If you don't want the older, now obsolete and/or broken code to be seen.... get a proper IDE with code folding. Using the VCS for this is definitely using the wrong tool for the job.

      If you try something obvious, and it doesn't work, odds are very good that the next bozo to come along is going to try exactly the same thing, and the odds are that they're not going to test it as well as you did.*

      You need to comment the code out, and you need to add a short explanation of why it doesn't work. E.g. // this looks obvious, but because of foo baz and kwok should never be attempted. YourName Date

      Then, when the idiot next in line tries to make exactly the change you said wouldn't work, (because you know that they will), and you are told to figure out why they broke the build, when you do figure out why it's broken, you can go back in the archive, pull out your previous attempt and explanation, and then clearly demonstrate that it isn't your fault.

      Version control is an archiving and accountability tool. Not something to magically hide the code until you need it, because if it that's how you use it, you'll never know that the previous version was there. Thus it fails at the most important thing code must do - communicating clearly to the programmers. And communicating what doesn't work (and why) is well over half the battle, more like 80 or 90 percent. (Yet another example of the Pareto Principle in action)

      TLDR: deleting old code to hide it epic fails the DRY principle

    4. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 1

      Not true with git. You can restore your repo from any of the checked out copies... And except with a one man show, you probably have multiple people that checked out the code. Just make sure the dev workstations don't burn down with the 'server' under the lead devs desk ;)

    5. Re:Version Control Is Your Friend by mwvdlee · · Score: 3, Insightful

      deleting old code to hide it epic fails the DRY principle

      The purpose was not to hide code, but to delete code.
      If code is no longer valid and maintained, it shouldn't still be available as if it were.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    6. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 3, Insightful

      Unless somehow your version control system somehow magically achieves the ability to imbue the knowledge of all the things that you tried and failed, and why they failed.

      Thats why you
      a) Comment well in your code explaining the algorithm being used, which gets preserved in VCS alongside the code
      b) Correctly document adding/removing functionality in the commit log

      If you don't want the older, now obsolete and/or broken code to be seen.... get a proper IDE with code folding. Using the VCS for this is definitely using the wrong tool for the job.

      This is about code removal (eg when refactoring, tuning etc). Not hiding.

      TLDR: deleting old code to hide it epic fails the DRY principle

      Quite the opposite generally. Usually when I'm removing code it's when I'm refactoring to generalise code precisely so it can be reused in multiple places. Keeping the previous code in place commented out would mean I was then repeating myself.

      When I have seen code where the developer's left in all the old code commented/disabled it simply makes the code look bloated and harder to read. Especially when the code blocks have changed so the code breaks the levels of {} indentation.

      You need to comment the code out, and you need to add a short explanation of why it doesn't work. E.g. // this looks obvious, but because of foo baz and kwok should never be attempted. YourName Date

      Rather than leaving in bloated code which in context will probably no longer make sense, it'd be better to have the correct functioning code only and in the comments where you explain what it does if there is an obvious but non-functional solution explain there what it is and why it's not done. If anyone really wanted to look at why then they can use a VCS tool to look at the first commit where that line appeared, and thus find the previous commit with the old code (or just use the date in your style suffix).

      I'm guessing your performance and thus pay/bonus is determined by the number of lines of code you have in production, rather than code quality (far harder to assess)?

    7. Re:Version Control Is Your Friend by Wonda · · Score: 1

      I wish more people did that, I've found old code with comments like /*can't work because of <x> */ where <x> was no longer valid more than once, and the code often only needs a few small changes to then work :)

    8. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 2

      You're nuts. DRY is basically about not having duplicated code doing the same thing in more than one place, or about doing the same repetitive process over and over when you could otherwise automate it. It has NOTHING to do with commented out dead code and leaving it around to rot. YOU are the reason nobody can produce a sensible set of "principles" for developers to follow. You extrapolate utter NONSENSE from said principles, and, most likely you keep your little list of extrapolations in your pea brain for others to stumble upon and wonder what the hell you were thinking.

      You don't use code as your primary communication tool, cube dweller. Communication happens continuously through code reviews and paired programming. It's organic. If your code base is so complex that you need to have an embedded running bullet list of "things you've tried that didn't work", one of two things are happening.

      1) The code base is so bloated and unreadable that it's descended into the land of a dying system (time to investigate some code complexity management tools, genius).
      OR
      2) You're a REALLY bad programmer who codes by throwing shit on the wall and seeing what sticks. Go back to school and learn some fundamentals.

      Comments in the code base _compliment_ a healthy communication pattern on a team. They're not a substitute for it. I've worked with people like you, and frankly if it were in my power you'd all be unemployed. In my shop, if you comment out a huge block of code (especially without a further explanation for why you didn't delete it), and I find it, you and I are going to have words, and I've proven my metal time and again for 20 years, so guess what, you lose.

    9. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 0

      EXACTLY. The previous poster is a nut job on multiple levels. I'd like to ask this genius if he MAINTAINS all that dead code. If not, then how the hell does he know it even works when he THINKS he can use his "comments as version control" to revert?

    10. Re:Version Control Is Your Friend by assertation · · Score: 1

      "Of course it does mean you need to actually learn how to use a version control system beyond blind forward checkins."

      and

      "Version Control Is Your Friend"

      People have laughed at me for liking MS Visual Source Safe. I am NOT a Microsoft fan by any means. However, the front end is so easy to use that Version Control actually became a convenient tool.

      Every other version control system I tried is a PITA in some way. It is true "Version Control Is Your Friend" but it doesn't feel like that. It seems like most version control software projects are determined to make things as complicated as possible.

    11. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 0

      deleting old code to hide it epic fails the DRY principle

      Riiight, so when I go to refactor your code, say rename a member variable, what do I do with the commented-out code (of which presumably 99% of your codebase consists by now)? Do I patch it with the new name, but not test it? Do I patch it and test it (assuming it works at all)? Do I ignore it since it's "just a comment" now? How's your DRY principle now that my refactor is going to go from an hour to a day?

      Communicating is well over half the battle, and having large swathes of commented-out fluff in all your functions is the epitome of poor communication. Data is not information. For your case (which is rare anyway) you want a comment describing what was tried, not a verbatim reproduction of the attempted implementation. Frankly, keeping every line of old code ever written and relying on code-folding to hide it is fucking retarded.

    12. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 0

      This is horrible advice:

      - Stop adding your fucking name and date in comments all over the place. Version control does this for you. I don't need you shitting all over the screen when I can just pull up the author and date with the "blame" command in every version control since ever.

      - VCS IS THE RIGHT TOOL FOR THE JOB. Relying your your IDE to fold commented out code is horribly the wrong tool. Please tell me "whoosh" and that this is just a troll. For the love of god. What happens when I refactor the code, do I need to go through all that commented out code too? No this is a terrible idea. Commented out code is simply unused and forgotten, there is no point commenting it out unless you just want to waste everyone's time.

      - Commenting out huge piles of code does nothing to communicate to your team what the program is doing. In fact just the opposite. You're simply making it harder to read.

      - Everything you have mentioned so far can be achieved with a single comment explaining what you have tried to prevent "epic fails". You don't need to comment out code to do any of that.

    13. Re:Version Control Is Your Friend by fatphil · · Score: 1

      > Unless somehow your version control system somehow magically achieves the ability to imbue the knowledge of all the things that you tried and failed, and why they failed.

      Give up programming now, please, for the sake of all customers of any products you may be involved in, and those poor souls you work with or who may have to maintain your slop in the future. It is *your* job to ensure that you include a sensible commit message with your code deletion. If you can't do that, you shouldn't be programming.

      Version control is your friend. If you're a dick, then you're a dick, and nothing will help you.

      > deleting old code to hide it epic fails the DRY principle

      Bollocks. Leaving redundant code in epically (notice that's an adverb, rather than an adjective) fails the DRY principle.

      No wonder you posted as AC. You should be embarrased of what you wrote.

      --
      Also FatPhil on SoylentNews, id 863
    14. Re:Version Control Is Your Friend by Anonymous Coward · · Score: 0

      Wait, so you are suggesting that code should never be deleted and should be left in the system, commented out, forever? Why on earth would you think someone was deleting code just to "hide" it? Old bad code is aweful. It should be purged immediately. I can think of very rare cases, such as you mention, where the obvious way didn't work for some obscure reason so you have to leave it there to warn people off. However, I can think of a great number of cases where old, deprecaetd code was commented out and should have been deleted instead.

    15. Re:Version Control Is Your Friend by defcon-11 · · Score: 1

      // this looks obvious, but because of foo baz and kwok should never be attempted. YourName Date

      Or you could do the correct thing, which would be to add tests that verify the behavior of foo and baz are correct in the case of kwok, then you're covered regardless of implementation. If the comment describes a performance optimization, you should describe why the current version works, rather than why the old version doesn't. Either way, your name and date are automatically recorded by your vcs, so you should never need to include that info in a comment.

  6. Ars by Anonymous Coward · · Score: 0

    3 days ago.

  7. Delete allllllll the code!!! by julianl · · Score: 1

    Delete it, and hope to god you didn't just break something.

  8. Source control by foniksonik · · Score: 4, Informative

    Who cares? You've got source control (SC) right? And you write unit tests right? If so then new code will pass the tests. If you write some benchmarks on performance then you'll know that too.

    Build early, build often, build against test coverage and you've got Continuous Integration (CI). If you've got CI and SC then anyone can write new code and it will either pass the tests or it will break the build. If it breaks the build use SC to pull that crap out.

    Done and done.

    --
    A fool throws a stone into a well and a thousand sages can not remove it.
    1. Re:Source control by Anonymous Coward · · Score: 0

      Ideally, code that breaks tests should never have been committed to version control in the first place, of course.

  9. Vigil by Anonymous Coward · · Score: 4, Funny

    Let Vigil delete your code for you when it's wrong and must be punished.

    1. Re:Vigil by rwaldin · · Score: 5, Informative

      Ah, Vigil! What a wonderfully amusing language...

      https://github.com/munificent/vigil

      But isn't a language that deletes code crazy?

      No, wanting to keep code that demonstrably has bugs according to its own specifications is crazy. What good could it possibly serve? It is corrupted and must be cleansed from your codebase.

      Vigil will do this for you automatically.

      Vigil deleted a function. Won't that cause the functions that call it to fail?

      It would seem that those functions appear to be corrupted as well. Run Vigil again and it will take care of that for you. Several invocations may be required to fully excise all bugs from your code.

    2. Re:Vigil by mwvdlee · · Score: 1

      Vigil deletes code that does not pass assertions (or "swear", as they call it).
      What mechanism prevents those assertions from being wrong?

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    3. Re:Vigil by Anne+Thwacks · · Score: 2
      What mechanism prevents those assertions from being wrong?

      Drinking sufficeint alcohol before pressing [Enter] is the standard mechanism. (It has been known to fail, but the results are not normally painful at the time).

      --
      Sent from my ASR33 using ASCII
  10. You may need to indicate that something is removed by Darinbob · · Score: 4, Insightful

    It's often good to just delete. Sometimes however I feel the need to put in a comment reminding the reader that the old functionality is gone. For example, it could say "no need to support device X here" or "input has already been validated". That's because it's not always evident to look in source code history to notice that there used to be something there.

  11. We do have written rules by eksith · · Score: 2

    Don't necessarily agree with this, but we comment out all older code when diffs aren't used. Commented code blocks with the date and editor's name works for small projects on a very tight deadline and this makes things easier if we want to rollback. Bigger projects do use diffs.

    As always, this is going to be a case of "works best for my situation", rather than just "best" method to do xyz.

    From the article:

    3.Is the manager/tech lead aware of the problem, and if not, why not?

    Since I work on contract, I don't renew if management has a chronic unawareness problem and more often than not, the problem is people. Clueless hierarchies are a symptom of a bigger disease, the brunt of which, I'd rather not take onto my shoulders.

    --
    If computers were people, I'd be a misanthrope.
    1. Re:We do have written rules by egcagrac0 · · Score: 1

      This. I don't worry about unwritten rules, I follow the written rules.

    2. Re:We do have written rules by Jorgensen · · Score: 2

      Please... Don't comment it out. If people want to see what it was like before, that's what version control is for. If you delete code, you should actually delete it.

      You should give the same courtesy to others as you expect from them: When reading code, you're interested in what it does, and how it does it. Not a history lesson.

    3. Re:We do have written rules by Anonymous Coward · · Score: 0

      Commented out code in production? Say it isn't so.

    4. Re:We do have written rules by eksith · · Score: 1

      Yeah, this is why I don't like it. I don't have much say in group projects though, so I just bear with it until the job's over. In solo work, deleted = deleted.

      --
      If computers were people, I'd be a misanthrope.
    5. Re:We do have written rules by tibit · · Score: 1

      Bigger projects do use diffs

      Huh? Maybe I'm overly disciplined, but for every commit of diff-able material, I always review the diffs before the commit. Even on throwaway single file projects. It has saved my from my human shortcomings, more than once.

      --
      A successful API design takes a mixture of software design and pedagogy.
    6. Re:We do have written rules by Anonymous Coward · · Score: 0

      When reading code, you're interested in what it does, and how it does it. Not a history lesson.

      Those who don't know history...

      If all of your history is hidden in your VCS, no one will read it.

  12. Sigh by styrotech · · Score: 1, Informative

    A link to a discussion on another site that was itself a link to a discussion on another site.

    I know it's easy stories, but really? Are the slashdot trolls really going to offer any unique and useful insights that Ars and Stack Overflow haven't already covered?

    1. Re:Sigh by Anonymous Coward · · Score: 0

      When I have too much faith in humanity, I go and moderate article submissions during the night. Also a good source of cheap crap and illegal pharmaceuticals. Not quite "enlarge your penis!" yet, but filled with crazy spam. I invite you to help when ever you can.

    2. Re:Sigh by Anonymous Coward · · Score: 0

      No, but then we get the opportunity to link to this discussion from another site.

    3. Re:Sigh by Anonymous Coward · · Score: 0

      Still living in 1998 perhaps?
      While you can find cooks, sockpuppets and even some genuinely stupid folks here, there are not so many trolls anymore.

    4. Re:Sigh by Anonymous Coward · · Score: 0

      You must be a blast to hang around with.

      "So what do you think about that latest news story"
      "Huh, well, I think they covered it pretty well in the news. No point discussing it now."

  13. There are only 2 important rules by OzTech · · Score: 1

    #1 Make sure your code is better.
    #2 If it isn't ... Don't get caught!

    1. Re:There are only 2 important rules by 93+Escort+Wagon · · Score: 1

      #1 Make sure your code is better.
      #2 If it isn't ... Don't get caught!

      You forgot...

      #3 ???
      #4 Profit!

      --
      #DeleteChrome
  14. Not Possible To Say by Anonymous Coward · · Score: 0

    If I posted them here, they'd be written rules. If you'd like to talk with me about them, you might be able to reach me at: 0118 999 881 999 119 7253

    Seriously, it's called refactoring. If you've never heard of it you really need to learn more about your craft. There are lots of books on it. Just saying you want to modify production code instead of releasing a new version says a lot about your development skills or that I read too much into people's questions.

    1. Re:Not Possible To Say by Alex+Belits · · Score: 0

      Seriously, it's called refactoring.

      It's called re-implementation that preserves interface. "Refactoring" is a stupid term made by stupid people who like to create new words for every trivial thing they see, because they don't realize that there is an infinite number of those trivial things, and their stupid new words pollute language.

      --
      Contrary to the popular belief, there indeed is no God.
    2. Re:Not Possible To Say by bfandreas · · Score: 1

      And "re-implementation that preserves interface" is a term you call elegant?

      --
      20 minutes into the future
    3. Re:Not Possible To Say by Anonymous Coward · · Score: 0

      +1

      http://en.wikipedia.org/wiki/Brainfuck
      It only has 8 keywords, it's Turing complete so can do any task a modern computer can do. Why bother creating new/more words for every trivial thing you see because they pollute the language?

      Because to be useful language (both natural and programming) has be capable of concisely capturing an idea! Otherwise it'd take you 10 minutes to explain something that you could do in just a few words.

    4. Re:Not Possible To Say by Alex+Belits · · Score: 1

      It's a description, and it's valid.
      Calling it "refactoring" is just as justified as calling the act of adding odd numbers to even ones "oddification".

      --
      Contrary to the popular belief, there indeed is no God.
    5. Re:Not Possible To Say by Anonymous Coward · · Score: 0

      "re-implementation that preserves interface" needs refactoring.

    6. Re:Not Possible To Say by Anonymous Coward · · Score: 0

      What a shitty analogy. Refactoring encompasses more than one thing, just like "mathematics" refers to more than one math concept.

  15. Agile/LEAN applies here by WinstonWolfIT · · Score: 3, Insightful

    Unused code gets deleted no exceptions. If there's no client demonstrating its value, its value is zero. The reasons are obvious in systems that scale into the hundreds of thousands to millions of lines of code.The way I describe it to my teams is, Just-In-Time development rather than Just-In-Case. You can have a conceptual framework in place and fill it in on demand without committing yourself to an orthogonal matrix of features that 'might be useful'.

    1. Re:Agile/LEAN applies here by Anonymous Coward · · Score: 0

      Of course... This argument applies to all comments as well.

    2. Re:Agile/LEAN applies here by kiick · · Score: 1

      That's so wrong. Imagine you are on the other end of this process, trying to use that code. You'll never be certain which combination of features exist and are supported and which have either been deleted or not implemented. If you have a logically orthogonal set of features, removing or not implementing a random subset just leaves gaping holes where your users are going to be very frustrated on the day they try to do something you thought was of "zero value".

      Just -In-Case development prevents problems in the future, which is what good programming does. Just-In-Time development is a shortcut and leads to incomplete code.

    3. Re:Agile/LEAN applies here by DragonWriter · · Score: 1

      That's so wrong. Imagine you are on the other end of this process, trying to use that code. You'll never be certain which combination of features exist and are supported and which have either been deleted or not implemented.

      Just-in-Time development does not mean that the current state of the system isn't communicated to users, and nothing in GPs description implied that.

    4. Re:Agile/LEAN applies here by WinstonWolfIT · · Score: 1

      The primary tenets of Agile are fast release cycles, an emphasis on work not performed, and delivered software being the only unit of value. The primary tenet of LEAN is an emphasis on elimination of waste. In an academic sense, a 'complete' implementation is more 'correct', but it can't be justified in business terms. Every software project begins and ends with a backlog and every unused feature delays delivery of a used feature. Every line of code, used or not, carries a maintenance cost. It comes up in searches. It slows down refactoring. It confuses developers.

      Every line of code not delivered has no Agile value. Every line of code not used at all has negative value.

    5. Re:Agile/LEAN applies here by Anonymous Coward · · Score: 0

      Perhaps you should loosen that tie? It seems to constrict the airflow...

  16. Clean code by Anonymous Coward · · Score: 0

    Read the book Clean Code by Robert C. Martin aka uncle Bob.

    and then watch the videos at http://www.cleancoders.com/

  17. My rules for deleting code by EuclideanSilence · · Score: 5, Funny

    Ok so you are working on a team and deleting code. Here are some basic rules to follow.
    1) Don't delete your boss's code. Just change all the function calls to go around it. If he asks you about it, say that someone else changed it.
    2) Don't cuss out the guy who's code you are deleting until after you are done. You might have to ask him why he did certain things (unexpected library behavior etc).
    3) Make sure the code you add to replace the old code is longer than what you deleted. That way, you can tell your boss that you added 'x' lines of code to the project.
    4) Don't waste time unit testing your new code. Obviously if you have to replace the old code, then you are a better programmer than the last one. If the last programmer's code passed unit tests, and you are better, then obviously yours would pass unit tests too.
    Any politeness the other programmer shows to you after you delete his code is not to be trusted. The code we write is pride to us, and deleting someone else's code is like seeing your coworkers girlfriend naked in the shower. Sure, it's not really your fault and you didn't really do anything bad. But expect some negative passive aggressive behavior in response.

    1. Re:My rules for deleting code by Anonymous Coward · · Score: 0

      You missed my favorite if you can get away with it. Send in the code with empty functions or completely deleted. Then add you code. That way the revision control shows that you added every line you wrote/plagiarized in place of the old code. It works great at my work they don't count deleted lines and unit tests are only done when a full build is started.

        BTW, they're putting me in-charge of a small team next week.

  18. Paid by the line by Anonymous Coward · · Score: 0

    I am paid by the line, I NEVER delete.

  19. Tests green, checked into git? by ratbag · · Score: 1

    Check your test suite covers all the functionality you want your program to have. If you're feeling paranoid, create a couple of tests that WILL fail when the undesirable code is deleted. Make sure everything is in the repo. Maybe branch/tag. Delete, repeat tests, roll-back or checkin (after deleting the canary tests added above) and move on to the next thrilling episode in your coding career.

    The first sentence of the paragraph above is of cours the killer - without a full-stack suite of tests there'll always be room for doubt.

  20. Our Rules by bloodhawk · · Score: 1

    Many places have standards for deletion of code, this is of course assuming by deletion you mean completed gone not just archived in source control. Deleting old code is like deleting history, if it is not there to learn from you are destined to eventually repeat the same mistakes. We never delete code that has been live and in production, comment it out or archive it off in source control, nothing that made it through to a live system is ever under any circumstances deleted.

  21. My rules: by Anonymous Coward · · Score: 0

    1) Just delete it (do NOT comment it out)
    2) Put the reason in the check-in notes

    Any decent version control system + sensible test suites will take care of the rest.

    Personally I can't stand it when people just comment out code. Either it is needed or not. Don't clutter up code files with useless junk...it will come back to hunt you, even in small projects.

  22. There used to be rules ... by inglorion_on_the_net · · Score: 5, Funny

    There used to be written rules for deleting code. Then someone deleted them. And since we don't use version control, we have no way to get them back.

    --
    Please correct me if I got my facts wrong.
    1. Re:There used to be rules ... by Anonymous Coward · · Score: 1

      The first rule of deleting code rules is no one talks about deleting code rules.

  23. Clean Code by Anonymous Coward · · Score: 1

    Apparantly my last post got deleted or somehow dissapeared:-(

    Code refactoring is well described in the book Clean Code written by Robert C. Martin AKA Uncle Bob.
    The Book contains some good examples on how to rewrite legacy code with a few wll picked hands-on examples.

    He explains a multitude of "rules" for modifying and deleting code, as well as testing it.

    If you want to remember his rules it is a good idea to pay for and watch the videos at http://www.cleancoders.com but it is not necessary.

  24. Whenever the program seems a bit slow... by Anonymous Coward · · Score: 0

    ...I just keep deleting code until the program runs faster! When the boss sees the performance figures go up, that's tangible progress you can take pride in!

    In any case, just delete lines of code at random until you observe malfunctions. If eliminating a line of code has no apparent effect, the code must be superfluous!

  25. Version and change management. by laxr5rs · · Score: 1

    Programs like SVN, TFS from Microsoft and GIT take care of remembering all the changes, of course. That's what I do for a living. With software change management using these programs, you can write any documentation you want as you can access any part of the code at any moment in time in its history. At my place of work, we are using the Scrum development process and past code isn't really worried about too much. In a sense we are always massaging all the code in the direction of satisfying clients, and making the code work better, while keeping track, using TFS of all the described items that were worked on as time goes along. We can access any file at any time along with its associated work items. From this any sort of story can be created about the deletion of code. The usual story in a busy business is that documentation is hard, so let's just move on.

  26. Don't break the API by White+Flame · · Score: 1

    Delete whatever you want behind a well-defined API barrier, as long as it still does the job when you're done.

    Delete entire unused and obsolete APIs where appropriate.

    Individual function bodies count as APIs, as well as large modules.

  27. Standard Practice by Anonymous Coward · · Score: 0

    Once the developer has left the organisation, then you delete all their code.

  28. I wouldn't delete any production code by Anonymous Coward · · Score: 0

    Use version control and do your changes on development code.

  29. I don't understand the question... by Foske · · Score: 2

    Either you use VCS, and you can' t ever delete code because you use it properly. Then the answer is: You can delete whatever you like in the latest revision. If you don't use VCS you have problems that exceed the scope of deleted unused code by a factor 1000, and you shouldn't be allowed access to ANY production code.

    1. Re:I don't understand the question... by Anonymous Coward · · Score: 0

      I have worked for a company that lacked version control for the project I was on, and didn't want to add it at that stage, even when approached about it.

      Fortunately they are using it on latter projects.

  30. ObBetteridge by Anonymous Coward · · Score: 0

    No.

  31. Simple 3 step procedure by sidevans · · Score: 1

    1. Don't delete anything, just comment out things
    2. Delete everything EXCEPT var_dumps etc (make sure the code works)
    3. Write a description in comments for functions / weird crap. Delete all unused code, indent with 2 spaces.

    at least if you make the code look visually nice, people think you know what you're doing.

    I do PHP, sorry purists.

    --
    I'm not signing anything
  32. Same as the rules for deleting Gods by Anonymous Coward · · Score: 0

    And just as hard to make it permanent ....

  33. This comment has been deleted ... by ElRabbit · · Score: 5, Funny

    ... for clarity

  34. Go step-by-step, don't directly delete it by Anonymous Coward · · Score: 0

    1. mark it as deprecated (although not every language has this option) so that nobody starts adding new calls to it

    2. find any place it is used and find workarounds/replacements

    3. comment it

    4. After a reasonable amount of time if nobody complains that it's been commented, delete it

    5. (D)VCS is your friend to revert any of the above.

    Points 6. and 7. are left to the imagination (lack thereof) of other ACs and FTFYs ...

    1. Re:Go step-by-step, don't directly delete it by bfandreas · · Score: 1

      Deprecation hardly if ever works. Once you deprecate something then you will have to get in touch with all of the clients of that function and make sure you won't break anything. And then you delete it. Marking that bit of code as deprecated does exactly nothing and can be safely skipped.

      If you are rewriting a function due to old cludgyness with asimple, elegant solution, then unit tests are your friend.

      If you are changing the behaviour of a function due to a change request then you still need to notify the maintainers of the clients of that function. It may very well be that they need to change their unit tests. Otherwise when theirs fail due to your changes they will want to know WTF is going on.

      Ah, the joys of distributed teams. Personaly I like the other guys well within punching distance.

      --
      20 minutes into the future
    2. Re:Go step-by-step, don't directly delete it by Anonymous Coward · · Score: 0

      If you're immediatelly going to break it (step 3), why bother with marking it obsolete (step 1)?

      As I understand it, the purpose of deprecation is to keep backwards compatibility for a while. This solution does not do that. Just delete the obsolete method right away, or mark it as deprecated for a while, then delete it. Either way step 3 is useless.

    3. Re:Go step-by-step, don't directly delete it by psmears · · Score: 1

      If you're immediatelly going to break it (step 3), why bother with marking it obsolete (step 1)?

      In order to ensure that step 2 doesn't take an infinite amount of time (by ensuring that, while you're finding places where the function is called and removing them, someone else isn't concurrently adding new calls...).

  35. Depends by Anonymous Coward · · Score: 0

    It really depends on the code itself.

    But generally, if the code is still useful as a guide or reminder, I'll comment it out, and then gradually delete the comment blocks as they lost their usefulness.
    If the code's useless from the get go, I'll just nuke it with holy hellfire without blinking.

    Captcha: discreet

  36. If there was *any* kind of consensus... by wonkey_monkey · · Score: 1

    ...on these unwritten rules, they'd have been written down a long time ago.

    --
    systemd is Roko's Basilisk.
  37. Mentioning the deleted code by rollingcalf · · Score: 4, Insightful

    At a previous employer, there was a *written* rule for deleting significant blocks of code.

    If a properly functioning block of code already in production was being deleted due to changes in business requirements, a comment should be inserted at or near the point of deletion, which mentions that some code was deleted and the original code can be found in version x.xx, and preferably a phrase saying what it did.

    However, if the code was not yet released to the production system, or was being deleted because it's buggy, it was acceptable to simply delete it without leaving a comment (if somebody needed to research an old bug they could look in the bug tracker, which would show which version of the code last had the bug, so there was no need to mention the bug-deletion in the code).

    --
    ---------
    There is inferior bacteria on the interior of your posterior.
    1. Re:Mentioning the deleted code by Anonymous Coward · · Score: 0

      Question, how helpful were those comments? In x years how many times did you ever use a comment to get an old revision?

    2. Re:Mentioning the deleted code by rollingcalf · · Score: 1

      Probably a total of a half-dozen times in the 3 or 4 years it was in effect. But that's largely because there was so much code already written before the policy was in effect, and it wasn't enforced rigorously enough. For example, code reviews didn't require going through a diff from the previous version, and code reviews weren't always done consistently and thoroughly.

      By contrast, there were a few dozen times when I was painstakingly searching through old versions to figure out if something was deliberately deleted vs. the programmer forgot to put it there in the first place. Appropriate comments would have saved time there. That was made worse by the horrible version control system in use.

      --
      ---------
      There is inferior bacteria on the interior of your posterior.
  38. That's what I do too, by jlehtira · · Score: 2

    most of the time I want to delete old code when I've written something newer to replace it. I keep the old code there for easy reference, until I'm confident the new code works at least as reliably as the old one.

    1. Re:That's what I do too, by iapetus · · Score: 1

      That's what the tests are for, surely? :D

      --
      ++ Say to Elrond "Hello.".
      Elrond says "No.". Elrond gives you some lunch.
    2. Re:That's what I do too, by davydagger · · Score: 1

      I do "all of the above"

      I keep the old code in comments while the new code gets some degree of testing, after which the old code is deleted.

      still with commits in version control.

    3. Re:That's what I do too, by bfandreas · · Score: 1

      You are being too polite.

      What that guy described was refactoring. Refactoring without unit tests causes all kinds of unforseen breakage. QA types rightfully become throughly pissed when they find devs haven't done their homework.

      --
      20 minutes into the future
    4. Re:That's what I do too, by bfandreas · · Score: 1

      I do hope that this "some degree" includes unit tests?

      Every time I see one of my devs click through 20 stages of an application to test stuff they have just written and it fails due to some obvious SNAFU I rip them a new one. That is what unit testing is for. Life is too short for anything else. I even only trust my own code after I've run a couple of unit tests against it. Only after that do I even bother to test it within the application. I'm far, far too lazy to do it differently.

      The old code isn't even useful anymore. Typically it isn't on the same screen where you write your new stuff but a couple of pages above it. Easy reference it ain't.

      --
      20 minutes into the future
    5. Re:That's what I do too, by iapetus · · Score: 5, Funny

      Unfortunately bitter experience prevents me from being too nasty on this one, because too many times I've been through the process of having good test policies in place, followed by senior management decreeing that in order to meet deadlines, testing and documentation will have to fall by the wayside 'just for a few weeks'. I know it would count as justifiable homicide, but I still can't afford the court time. ;)

      --
      ++ Say to Elrond "Hello.".
      Elrond says "No.". Elrond gives you some lunch.
    6. Re:That's what I do too, by bfandreas · · Score: 5, Insightful

      Well, I am management. And I prefer to actually deal with stuff.
      If the timeframe is borked, then I need to know so I can talk to the client about cutting features, postponing release, release in stages, etc. There is a lot you can do. But shoving out stuff that doesn't work or is unrelyable is something that will never be properly resolved.
      If you desperately try to meet the release date and you actually somewhat succeed, then the books are closed on that release. But if you spend a lot of time after the release on bug fixing then eyebrows will be raised and your competence as a developer will be questioned. It's not your job to make management happy. It's management's job to make your job possible.

      On unrelated news: Overtime is a clear indicator of management failure. Also massive overtime to meet deadlines never work and is never worth the effort. Been doing this for 15 years and I yet have to encounter one instance where this actually proved to do more good than harm.

      --
      20 minutes into the future
    7. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Yes, and your preferences don't matter one jot if *your* manager is on a bonus for hitting a deadline.
      And as usual it's us Indians that end up taking it up the pupper.
      So excuse us if we quietly comment out code with a TODO, a comment, a ref to the trouble ticket, and a note in version control.

    8. Re:That's what I do too, by cultiv8 · · Score: 1

      True Story: I have a client, a major university whose name you would most likely recognize, who back in January 2012 senior management made the decision to take their Tier 1 site (read: XYZ.edu) off of version control in order to meet deadlines.

      1 year later and they are still not on version control, they still aren't doing daily backups, and there are no versions of the site that exist other than the site hosted on Rackspace.

      --
      sysadmins and parents of newborns get the same amount of sleep.
    9. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Why is overtime always a management failure?

      I work side jobs primarily so I get exposure to different things; I enjoy it and it pays better than my day job so it provides an entertainment budget which otherwise wouldn't exist. Recently I was asked to help a different unit within my place of employement; it was doing something really different and they asked about paying my home unit so borrow me for awhile. Given our deadlines, that's not possible, but I'm trying to get permission to focus my day hours on my day job and evenings helping out this side unit (they're very important for the company and just had to fire their whole local I.T. department for cause). They've suggested a bonus, I've suggested its less paperwork if we just get some money transferred into our budget and I get to go to some training of my choice; I've done other things which were for free but helping friends out so the money is just a perk since that unit has plenty.

      I'm honestly asking as I'm now in a supervisory position so I'm really trying to grow my soft skills.

    10. Re:That's what I do too, by JD-1027 · · Score: 1

      From my experience as well, you are the exception and not the rule. And it doesn't even matter if your immediate manager is good at this kind of thing (mine is, just like you). If it is the upper management putting the hammer down on our manager, then their hands are tied. Sorry, but if I've put in a full day and have to choose between getting something out the door before I'm comfortable with all my testing or seeing my kids for an hour, that is a pretty easy choice for any good parent.

    11. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Your spellchecker is unreliable, that's for sure!

    12. Re:That's what I do too, by Anonymous Coward · · Score: 0

      FYI:

      Pupper ?? Perhaps a puppy.

      Pooper = Lund = Bunghole

      Also: I coded after a dot indian, you guys have no room to complain.

    13. Re:That's what I do too, by HornWumpus · · Score: 1

      If they had to fire the whole IT department for cause there was clearly a management failure.

      You answer your own question.

      That said you can't change history. You need to do failure analysis (why did the IT department go out of control) without blinking. Which is tough as the failure analysis will likely point to someone who wasn't yet fired and has power ((s)he will, no doubt, be pointing at the top IT person that is already gone). This process needs to be private. If people can't speak freely during this process it should tell you to start shopping your resume around. The place is fucked from the top.

      The first step in that failure analysis is accepting that there was a management failure that led to the need for massive overtime.

      --
      John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
    14. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Well, I am management.

      It's not your job to make management happy. It's management's job to make your job possible.

      +5 Troll, anyone?

    15. Re:That's what I do too, by Anonymous Coward · · Score: 0

      On unrelated news: Overtime is a clear indicator of management failure. Also massive overtime to meet deadlines never work and is never worth the effort. Been doing this for 15 years and I yet have to encounter one instance where this actually proved to do more good than harm.

      May be an indicator of management failure - in the sense that any failure is ultimately a management failure. If it is a failure.
      In practice, do you have ten developers at one million per year total regardless of need, or do you have six developers and ask them to do 1.5 FTE equivalent overtime during your crunch times for nine hundred fifty thousand per year labor total? Or do you hire four additional developers when you need them and fire them at will for eight hundred fifty thousand per year? Which of those three builds the best product in the short term, and provides both the best customer experience and the best employee satisfaction in the long term?

      Overtime is a tool, nothing more nor less. I'd rather meet a client deadline if possible, by the means available. Whether it is good, a necessary evil, or an avoidable pitfall is utterly dependent upon context and subjective opinion. (Me, I'd rather be home than at work, so I avoid overtime personally whenever possible.... and still have to do some once in awhile.)

    16. Re:That's what I do too, by tibit · · Score: 2

      What kind of version control do they use so that getting rid of it saves time? Do they tar it to half inch tape upon "commit" and write the commit message in a paper logbook? The fuck?

      --
      A successful API design takes a mixture of software design and pedagogy.
    17. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Overtime can also be a clear failure of the client to start the process early and their willingness to part with large stacks of cash in order to get the project done on time.

    18. Re:That's what I do too, by Kjella · · Score: 1

      It's not your job to make management happy. It's management's job to make your job possible. On unrelated news: Overtime is a clear indicator of management failure.

      I'm not opposed to overtime, just sustained overtime or overtime without pay. Even with the most reasonable plan sometimes shit happens, The estimates were completely off, the assumptions were completely off, people quit or fell ill, the foundations turned out to be quicksand, even without crazy last minute meddling from upper management or marketing sometimes you're way off track. Particularly in all kinds of compliance projects the deadlines and requirements are fixed but also in other situations the consequences are huge.

      --
      Live today, because you never know what tomorrow brings
    19. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Yay for this quote: "It's not your job to make management happy. It's management's job to make your job possible." Refreshing. I'd work for you. ;)

    20. Re:That's what I do too, by bfandreas · · Score: 1

      A plan is a sequence of events that are guaranteed not to occur in that order.
      If you rely on your projections and initial planning will actually happen in that way then you are properly fucked. Planning is an ongoing process and should be treated as such. I've been on the receiving end of enough death marches to know that the "final push" will only leave you shot to bits and bleeding in nomansland. There is always an alternative. But you need to be looking for one soon enough. When the shit has hit the fan then it is too late. You have to react while the poo flinging monkey is eating a substential meal and the servicemen start wondering what to do about air circulation. You might be able to catch the poo in mid-air. Brown hands are preferable to brown faces.

      --
      20 minutes into the future
    21. Re:That's what I do too, by Kjella · · Score: 1

      It's not your job to make management happy. It's management's job to make your job possible. On unrelated news: Overtime is a clear indicator of management failure.

      (Note, I hit submit instead of preview on my other reply) I'm not opposed to overtime, just sustained overtime or overtime without pay. Even with the most reasonable plan sometimes shit happens, The estimates were completely off, the assumptions were completely off, people quit or fell ill, the foundations turned out to be quicksand, even without crazy last minute meddling from upper management or marketing sometimes you're way off track. Particularly in all kinds of compliance projects the deadlines and requirements are fixed but also in other situations the consequences are huge.

      Now let me tell you that my baseline is working 40 hours a week, it might be different if you're already doing 60 but I don't work as hard as I could. This is because I generally like to have a life outside work, For a decent enough compensation - usually +50% or +100% in addition to my regular hourly pay - I'm willing to work harder for a limited time. Of course there's a potential for abuse here in slacking and getting overtime pay to stay late to fix it, but management will quickly pick up on that. When shit happens, they know they have an extra gear that costs extra money. And they use it, but they don't use it for no good reason and there's really no way to abuse it since you're burning more money than hiring more people to work regular hours.

      --
      Live today, because you never know what tomorrow brings
    22. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Thanks for posting this.

    23. Re:That's what I do too, by cultiv8 · · Score: 1

      It's what happens when a marketing department develops a website. "git commit? push? pull? Jesus, I just want to make a quick change. Here, let me start up Dreamweaver and I'll make a change on the production server".

      --
      sysadmins and parents of newborns get the same amount of sleep.
    24. Re:That's what I do too, by Anonymous Coward · · Score: 0

      Overtime is a clear indicator of management failure.

      In the game industry, overtime is business as usual.

    25. Re:That's what I do too, by Anonymous Coward · · Score: 0

      where do you work? i want you to be my manager!

    26. Re:That's what I do too, by tibit · · Score: 1

      Yeah, I understand there are idiots like that, even entire idiot departments. To me, it doesn't matter what department develops a website. The IT people should train them in the use of the tools. If they don't like it, there's surely many brighter applicants with drive for the job who'll learn the ropes. With tortoisegit the whole "process" is just a couple of clicks.

      --
      A successful API design takes a mixture of software design and pedagogy.
    27. Re:That's what I do too, by erp_consultant · · Score: 1

      I wish that more managers shared your view but, sadly, that has not been my experience. A common problem I see is that if a project falls behind schedule management will decide to bring more people in to try and get it back on schedule. I think it's well meaning but it just rarely seems to work. You spend more time training up the newbies and it takes away from your current duties and adds to the confusion.

      "But if you spend a lot of time after the release on bug fixing then eyebrows will be raised and your competence as a developer will be questioned." - Spot on. As a developer I feel that my job is to deliver bug free (or as close to it as possible) code. I would rather skip a feature or two and at least deliver stuff that works. Once your client starts to question your competence you're finished.

      "Overtime is a clear indicator of management failure." - A little overtime is fine but, as you said, massive overtime means that someone dropped the ball when the project schedule was drawn up. As a consultant what I sometimes see is that a salesperson will make all kinds of outlandish promises to get the contract - typically by underbidding the competition - and then hand that mess over to the PM who has to try to make it work. That leads to the massive overtime and a poor quality product, not to mention a burned out crew.

      Personally I think the problem stems from how salespeople are typically compensated. They will often get a percentage of the contract price as a bonus which encourages this type of behavior. It does not take into account profitability at all - only the bottom line contract amount. So if cost overruns occur it's not the salesperson's problem. They still get the same bonus and could care less if the project team has to put in tons of overtime to meet unrealistic project schedules. I think a better way is to pay the salesperson's bonus on the back end, or perhaps at project milestones - based on profitability not revenue. That will discourage the lowball bidding game that so often occurs.

  39. The rules by tp_xyzzy · · Score: 0

    1) Adding new code is always ok. Just need to keep it independent of the old code. Avoid modifying intersection of old code and new code.
    2) Modifying code is dangerous. It can break features anywhere in the system.
    3) Deleting code is extreamly dangerous. It can both break code, and lose information what was original code version.

    No amount of version control hacks is changing these rules.

    1. Re:The rules by viperidaenz · · Score: 1

      So your answer is to never change code once its written and just hack on the sides if behaviour needs changing?

    2. Re:The rules by tp_xyzzy · · Score: 2

      It's more like breaking already tested code is wasting too much time...

    3. Re:The rules by iapetus · · Score: 3, Interesting

      1. Not always true by a long way, especially when you're coding for devices with limited space. It can also lead to unnecessary duplication, overly convoluted logic to avoid modifying existing code, unnecessary duplication, poor performance and unnecessary duplication.

      2. Bug fixes are dangerous? Really? That could have saved me a lot of time at my job before last. :D

      3. If you think deleting code causes information to be lost, you need to review your source code control policies. Now. Yes, it can be dangerous to remove crufty looking old code, because it frequently contains years worth of minor fixes to deal with bizarre edge cases, device oddities and the suchlike. But you know what? Those should all be well commented in the code, and covered by appropriate tests that will ensure your new version works too. If they're not, you might need to review some other policies as well.

      --
      ++ Say to Elrond "Hello.".
      Elrond says "No.". Elrond gives you some lunch.
    4. Re:The rules by tp_xyzzy · · Score: 0

      1. naah, it causes no such things.
      2. It's not about bug fixes. That is handled by not writing broken code in the first place. If you need to write same thing twice, you're wasting time the first time you wrote it. You should review your code policies if you have large number of bugs to fix.
      3. information lost = noone bothers to rewind the version control history to find the exact version of the software that actually works. It needs to work every day and every week for years. It's not enough that half the versions are working and the rest need to be reconstructed from version control histories. Everything in version control must work. Deleting code is dangerous because you cannot track all dependencies from the deleted code to the whole system.

    5. Re:The rules by iapetus · · Score: 3, Insightful

      1. Good rebuttal. No, seriously, proof by dogmatic assertion is great.

      Of course it causes all these things. If you're refusing to modify existing code, then you can't refactor it to handle extra cases, which is going to lead to unnecessary duplication (and probably hideous cut/paste code). It will expand the size of the codebase, because this is what happens when you add code, which will eventually cause problems on some platforms (trust me - I've been there).

      2. Turn in your coding license. Now. Except for a very small subset of coders working on very specialised projects and using formal proofs of correctness, anyone who claims their code contains (or should contain) no bugs when first written is a fool, and a dangerous fool at that.

      3. That may be your experience. Rolling back version control history to find out where defects were introduced can be very useful, and if the tools are good enough (which they are) it isn't exactly difficult either.

      As for the idea that you can't track all dependencies from the deleted code to the whole system, if that's true to the extent that you claim then your design is screwed.

      --
      ++ Say to Elrond "Hello.".
      Elrond says "No.". Elrond gives you some lunch.
    6. Re:The rules by tp_xyzzy · · Score: 0

      > Of course it causes all these things. If you're refusing to modify existing code, then you can't refactor it to handle extra cases

      This is already covered by the rules. What you're describing is part of the "intersection" of old code and new code. Avoiding those changes as far as possible is the correct route (but the new code still needs to be integrated to the system so that it's executed as part of the program's execution). But writing independent module first, and then integrating it carefully to the system is the correct route. Just need to be more careful with the intersection, since all those modifications are dangerous.

    7. Re:The rules by Bigby · · Score: 1

      Bugs are relative. I don't write bugs; others only claim a write bugs. Since the client is among those making the claim, then I change the code to remove what they call a bug.

    8. Re:The rules by Bigby · · Score: 1

      And "others only claim a write bugs" is not a bug. It only doesn't conform to your people's version of the "English language". But I will correct it to help others that don't read my language: "others only claim I write bugs"

    9. Re:The rules by viperidaenz · · Score: 1

      But you need to test it again anyway, since the unchanged code's input may have changed or the output may need changing.

      Just because you haven't changed a particular piece of code, doesn't mean you shouldn't test it again.

    10. Re:The rules by defcon-11 · · Score: 1

      immutable source code? The problem with this is that someone will inevitably add new calls to the old function (with it's broken behavior), even if it's marked as deprecated.

    11. Re:The rules by Anonymous Coward · · Score: 0

      What the fuck are you talking about? Have you ever done any coding before?

  40. The first rule by Anonymous Coward · · Score: 0

    The first rule of code reuse is - the code must be worth reusing.

    If you're not sure, put it in a fucking SCM & delete away.

  41. ngsource is great for config/code storage by Anonymous Coward · · Score: 0

    We have quite approx 20 people in our team that can be working on various things from VB Code, SQL Statements, router configs, anything text based that can be modified. We have been using ngsource for some years now and its worked very well for us http://www.ngsource.com/SourceControl.htm I'd suggest using this for the basics of version control, etc.

    1. Re:ngsource is great for config/code storage by XcepticZP · · Score: 1

      Nothing new here that traditional, more established VCS systems can't do. Stick to SVN/Mercurial/Git. Advertise your own product much, AC?

  42. Seriously by OzTech · · Score: 1

    While RCS may be well and good, it won't necessarily show what was deleted or why.

    My rule of thumb is to comment out the old stuff, and date it. If it is still there after a few months and the new stuff has been working without anyone noticing or commenting (in a negative fashion), this it's pretty safe to delete it and leave any history/archiving to RCS. Before doing the final delete, I will usually still put a comment in the function/proc header (if I hadn't already done so) about the deletion/major-change as this is more often than not the only thing that is really seen.

    1. Re:Seriously by Anonymous Coward · · Score: 0

      >>it won't necessarily show what was deleted

      svn diff filename

      >> or why.

      svn log filename

      Sorry for being Subversioncentric.

  43. Simple: Don't by RedLeg · · Score: 1
    If you have a version control system in place. it's not an issue cause you can roll back or at least see the previous versions.

    If you're operating on a more basic level, clone the crufty code, put the cruft in comments explaining CLEARLY why you cut it out.

    When you fix or replace what you cloned, comment there as to exactly what you think was wrong or broken, and how you fixed it.

    One thing that is certain, with production code, you will NOT be the last person to work on it. Pay it forward with good practice.

    Red

  44. Use Version Control!!! by Big+Hairy+Ian · · Score: 1

    Personally I use the "Back Space" key but I have heard of strange perverted creatures who use the "Del" key :)

    --

    Build a Man a Fire, and He'll Be Warm for a Day. Set a Man on Fire, and He'll Be Warm for the Rest of His Life.

  45. I have a great idea by Chrisq · · Score: 4, Funny

    The more you can delete, the better.

    Starting from the Murphy's law on programming: Every non trivial program has at least one bug

    You can derive by rigorous analogy the Murphy's law on not-programming: Every non written code has exactly zero bugs

    I have it - the holy grail, the key to bug free coding. If the deleted code has no bugs just restore the deleted lines and delete the rest. You will then have bug free programs.

    1. Re:I have a great idea by Anonymous Coward · · Score: 0

      All well and good unless you delete the code that keeps it from having a bug.

  46. The first rule - If only that were true. by Chrisq · · Score: 1

    The first rule of code reuse is - the code must be worth reusing.

    If you're not sure, put it in a fucking SCM & delete away.

    If only that were true. I once worked in a team where someone had written a function which took an integer and returned the same value (they were blindly following a pattern where a converter was called stringToInt, intToString and wrote an intToInt because "other cases called a function"). Two other developers had subsequently used this function (copy/paste programming)!

  47. Uhm delete it? by viperidaenz · · Score: 1

    Delete it. Plain and simple.
    Put a comment/bug id in the commit log.
    What's the problem?

  48. Re:Simple: Don't by viperidaenz · · Score: 1

    Pay it forward with good practice, don't comment out code. Comments are for comments, not code.

  49. The rules were simple by Llian · · Score: 1

    The rules were simple for this, but they got deleted.

  50. version control and start/end with working code. by Barryke · · Score: 1

    Rewriting code?
    version control + start from a working situation and end with a working situation. Where working situation means bugfree and no broken parts other than those that are going to be rewritten.

    Deleting code?
    version control.

    --
    Hivemind harvest in progress..
  51. Don't ask don't tell? by SpaghettiPattern · · Score: 1

    Don't ask don't tell?

    --

    I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
  52. Re:Simple: Don't by asdf7890 · · Score: 1

    Commenting just code is fine for temporary testing/debugging/rewriting.

    Leaving code in a commented state is a comment ("this is how something used to be done here"), but not a terribly helpful one. If you find yourself doing this, as well as commenting the code add a true comment stating why and what code replaces its function (the bit above, the bit below, something elsewhere, nothing (it is truly deprecated)?) and why.

    Once some time has passed, unless the change is significant and there is a chance someone will come along and "unchange" it not knowing the history, such comments along with the commented code should be removed as it is all in source control anyway - but keeping it in your face (and the faces of other people working on the code) in the short term can sometimes be quite helpful especially in the case of code several people are actively looking at as one of them may quickly spot a flaw (which may otherwise go unnoticed for a while longer) that makes your new more clean/fast/bugless code far less perfect than you first thought.

  53. Oxymoron by Anonymous Coward · · Score: 0

    If we told you, they'd no longer be unwritten.

  54. Only one rule. by Alex+Belits · · Score: 1

    There is only one rule -- don't replace better code with worse code.

    --
    Contrary to the popular belief, there indeed is no God.
  55. Software Engineering by petur · · Score: 1

    Follow your software design criteria and your design documents, then it should be clear. One should not simply sit down and hack away changes without careful planing.

  56. It's simple by codekavi · · Score: 1

    Delete, early, delete often

  57. Code is a liability by Anonymous Coward · · Score: 1

    "Functionality is an asset, code is a liability." -- Damien Katz

    If the code is not used you should not have the burden to maintain it. Delete it if you can. Even commented code needs to be maintained.

  58. Remove clutter, leave information by Mascot · · Score: 1

    In the largest company I've worked for, the written rule was to explain and comment (using a specific syntax), never delete. The unwritten/save-our-sanity rule was to delete if the comments began affecting the readability of the code.

    When working on code with hundreds of other developers, code that's commented out and explained/linked to a case id, can save a _lot_ of time. Say a piece of code solved an issue, but in turn created a performance issue. This did not become apparent until the code went live. The developer tasked with figuring it out isolates the affected flow and "... oh... someone added that credit check here a few weeks ago, I'll check that out first." That saves a lot of time compared to identifying dozens of involved files, then only diffing the specific methods involved in the particular flow.

  59. The rules aren't actually unwritten by Anonymous Coward · · Score: 0

    They're just deleted

  60. Subversion or Git by flyingfsck · · Score: 1

    If you feel that you need to leave deleted code in comments for a while or forever, then your version control system isn't working. Simple as that.

    --
    Excuse me, but please get off my Pennisetum Clandestinum, eh!
    1. Re:Subversion or Git by Wonda · · Score: 1

      Not really, when code needs to be optimised the resulting quick version can sometimes be unreadable, I just keep the old clear but slow version as the explaining comment in that case.

  61. production vs. development code by Anonymous Coward · · Score: 1

    don't mess with production code.

  62. Reminds me... by Anonymous Coward · · Score: 0

    One company I worked for a few years ago happened to be using Java. They had a summer intern who wrote a bunch of time scheduling code – a couple thousand lines IIRC – to manage doing things at the correct time across different time zones. Then said intern went back to school. Three months later, when daylight savings ended, everything was off by an hour. I looked at it and found it didn't deal with leap years correctly either.

    I deleted – yes, just deleted – two thousand lines of code and replaced it with about five lines to call a routine in the Java runtime library. As I recall the intern spent the whole summer working on this one piece of functionality that should have only taken about five minutes to write. They could have done a lot of other more interesting things instead.

    Stupid.

  63. What I do... by Anonymous Coward · · Score: 0

    If the deleted code is only a few lines, and the code represents an obvious solution, then I will comment out the code, along with a comment why the code is not suitable, e.g. "this doesn't work because blahblah".

    Otherwise I just delete it, source control etc. If the newer code has a problem we can revert it.

  64. Standards by Anonymous Coward · · Score: 0

    The standards depends on the editor / IDE. There are a wide variety of choices from the classic C-h (^H), all the way to mouse editing.

  65. Never delete.... by Anonymous Coward · · Score: 0

    Never delete, ever. Comment out. All the version control in the world won't help you if it turns out that you ignored this 20 versions ago and now don't quite recall whether it was 20, 21 or 22 ago...

  66. How to delete code by ignavus · · Score: 1

    Keep deleting code from a program until it doesn't work. Then put the last bit back.

    It is now as small as it can be, and it works. Voila!

    --
    I am anarch of all I survey.
  67. Two Unwritten Rules of Code Deletion by retroworks · · Score: 1

    Unwritten Rule #1;

    .

    .

    Unwritten Rule #2:

    .

    .

    The other rules offered here are good, but with all due respect, they've been written.

    --
    Gently reply
  68. IDEA by sproketboy · · Score: 1

    Right click, find usages. Then do safe delete.

  69. the rules... by sonamchauhan · · Score: 1

    1. Don't be a theorist -- profile your code! Only consider code for deletion that's not actually used in production
    2. If the code you want to delete code can't be profiled (e.g. its within a method), be creative... refactor it out into a method and profile.... Or write a log entries to disk.
    3. Now delete the code - be bold!
    4. ... But make sure your tests pass
    5. Get your change reviewed
    6. Get your build UAT tested by 'the business'... perhaps by bundling with other minor changes
    7. Along with a deployment plan, have a rollback plan (and a rollback build).

    You notice I didn't say "use version control". Version control is good for managing the development process. Its not a shortcut to manage the entire software change process.

  70. Rule 1: You Don't Alter Production Code by assertation · · Score: 1

    I don't alter production code, ever.

    If I alter code it is going to go through a test release and be tested by other people first.

    I've been programming for 14 years and I've learned no matter how trivial a change I make it is very possible to do damage unless the changes are completely tested.

    So, I never alter production code, only code that is due to go through a testing cycle.

  71. My system by Anonymous Coward · · Score: 0

    I've got the best system - Every release, I zip my source and move it to a folder with every version, 0.1 to 2.7.63

  72. Simple by Opportunist · · Score: 1

    1. If it works, don't touch it.
    2. If it does not work, find out who did it and slap him (optional) and make him make it work.
    3. If you cannot find the one who did it (or if he has been rightfully fired already), scrap and redo.
    4. If code needs modification, do not modify the code but work around it.
    5. Never EVER delete code. 9 out of 10 times you'll have to change it back anyway.

    --
    We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
  73. My personal strategy... by DigitalSorceress · · Score: 1

    My personal strategy is to first comment it out and put up a nice big comment saying why I removed it and when... then, at a later date, I'll actually remove it.(and comment appropriately about it in check-in)

    --

    The Digital Sorceress
  74. refactor versus rewrite!?! by ayahner · · Score: 1

    I can't say I'm shocked to see all these comments advocating commenting deleted code. I wish you would make it easier on the hiring managers and put in your resume that is your preference so we can weed you out of the hiring process.

  75. Rule #1: Understand what you are deleting by Anonymous Coward · · Score: 1

    Years (now decades) ago I worked with a programmer who routinely replaced working/tested code with his own "streamlined" code that solved the specific problem in front of him. In other words, he deleted code that worked in the real world and replaced it with his code that solved for the test case. When asked what he was thinking, he said, "I didn't understand that code, so I replaced it with my own."

    The short term result was chaos within the organization because the QA department "wasn't finding bugs" that were showing up in the field. The intermediate result was that he lost his job. The long term result was a whole bunch of hours taking out his changes and reverting code to its behavior before he was involved (not always easy after a few years).

    If you don't understand code, don't delete it.

  76. Rules of Code Modification by gargleblast · · Score: 1

    An impressive number of interrelated questions for an Ask Slashdot! Let's start by dispensing with the red herring that a bewildering number of commenters have seized on: commenting out code versus deleting code. If you have source control, then from a point of view of history as well as a point of view of executable / deliverable, commenting out code is exactly the same as deleting code.

    Right! Now for your questions:

    The answers may be somewhat language-dependent ...

    1. No, there is no language dependency.

    What best practices do /.'s use when they modify production code?

    2. (For beginners) Don't.
    3. (For experts only!) Before it goes to production, test your code or (better) have someone else test your code.

    Generally-accepted best-practice documents regarding code rewrites.

    4. If it is a complete crock of shift, rewrite it.
    5. If it is only mostly shit with some gems mixed in, refactor it instead.

    Generally-accepted best-practice documents regarding code deletion / What are the unwritten rules of deleting code?

    This is a special case of code modification, with a large number of possible reasons why it might be the right thing to do:
    6. If it is not linked in, delete it.
    7. If it is never called, delete it.
    8. If it has conditions that are never met, delete it.
    9. If it has no purpose, worth or value, delete it.
    10. If it has too little purpose, worth or value compared to the cost of maintenance it imposes, delete it.
    11. If it is performance code and it has no associated performance test, it has too little purpose: see point 10.
    12. If you change your mind, put it back.
    13. If your fellow programmer objects, then state your reasoning, but give them permission to put it back.

    Generally-accepted best-practice documents regarding code modification.

    14. See point 3 above.
    15. If your tester objects, you screwed up mildly.
    16. If your user objects, you screwed up badly.
    17. Don't screw up badly.

  77. Nothing here... by fatp · · Score: 1

    If it's posted in /., it is no longer unwritten.

    Whatever you post / read here are NOT the answer of the original question.

  78. Re:You may need to indicate that something is remo by llZENll · · Score: 1

    If you are deleting functionality I highly suggesting leaving a permanent comment in saying what was deleted and when. Specs change all the time and the code may be needed in the future, a one line comment and hunt to SC will save from rewriting the functionality in the future. Without comments no one is going to search for it and it is lost forever.

  79. Proper commit messages are key by Anonymous Coward · · Score: 0

    When relying on version control, proper commit messages are the key to ensuring that you can easily find the right code later. We have these broken into 4 catagories:

    AUTHOR_IS_ASSH__E The person who wrote the code isn't too bright
    CODE_IS_SH_T We may like the person who wrote the code is actually bright, but may have had a bad day, ie was drinking a lot before committing
    CODE_IS_USELESS Code is beautifully written, elegantly designed, but that was what we wrote before management decided what the project should do
    CODE_TOO_SIMPLE Code is not complicated enough to ensure our presence maintaining it for the next 30 years, time to complicate it, pronto.

  80. The rules are not unwritten by rot26 · · Score: 1

    They WERE written but then deleted. Search the git repositories for a few hours and you will find them out there somewhere.

    --



    To ensure perfect aim, shoot first and call whatever you hit the target
  81. Eliminate overtime by Anonymous Coward · · Score: 1

    Declare all involved "Exempt" and work them like galley slaves!

  82. Let the Tools do the work by AttillaTheNun · · Score: 1

    Delete the code - it's the version control system's responsibility to maintain change history. The IDE should provide some non-intrusive visual indication of sections of code that have changed in the prior version. This provides the necessary alert and the developer can investigate version control for the details.

    I don't know how many, if any, IDEs support this feature, but it seems like a good idea to me.

  83. Zombie code by drolli · · Score: 1

    sometimes if deleted bad code keeps showing up in the repository you need to be careful and keep the wooden stick an the hammer ready to kill it in a man-to-code combat on the local harddrive of some developer.

  84. unwritten rules by Black+Parrot · · Score: 1

    #1: Don't write the rules.

    --
    Sheesh, evil *and* a jerk. -- Jade
  85. Production Code by JWSmythe · · Score: 1

        Oh my god, you can't delete code! It worked for us in 1998, and it's still working on our circa 1998 machines. What the hell are you thinking?!

        Kidding aside, I comment and date old code, and add new code. It's not only there for restoration purposes (ya, ya, version control and stuff are there too), but if someone gets a new great idea on adding new code, they may find exactly that has already been removed with good reason.

        When it's my own code that I maintain with no one else, I ditch the old commented code after about a year. Sometimes it sits there for longer, because it was actually good code that didn't suit that particular purpose.

        I have one chunk of code in particular that won't get ditched for a longtime. It's a HTML filter, that takes all kinds of Microsoft specific characters and converts them into HTML friendly characters. I did it up better with a much smaller chunk of code, that can do a lot more, but occasionally I reference those old bits.

    --
    Serious? Seriousness is well above my pay grade.
    1. Re:Production Code by minstrelmike · · Score: 1

      mod the parent up.
      Code you can read the history of right there in front of you is not the same as code hidden someplace in the version control system.
      Many times the 'bug' is not a programming error; it is more of a user-desired update that didn't quite work for some reason. Having that reason right there in the code saves the developer a lot of time trying to re-implement it 18 months later when some new manager comes on board.

  86. Be bold by Brian+Kendig · · Score: 1

    As Wikipedia says, "Be bold." If you see code that needs to be deleted, delete it. Don't just leave it commented out and taking up space.

    If you're removing functionality, then make sure you note this clearly in your commit summary, so that it can be found again if that functionality needs to be put back in.

    Also, the article talks about rewriting code - throwing out the old and creating it again. This is generally a bad idea, even if you're starting with bad code, because all a rewrite does is exchange a known set of bugs for an unknown set of bugs.

  87. Why not just delete it right away? by Anonymous Coward · · Score: 0

    Some people don't use a ticketing system to track their requirements, so have no other form of documentation for what the program does than what is in the code itself. This is especially problematic in houses where even the requirements documentation is just a doxygen header in a file written by a guy who left years ago.

    You make a big change to production? There should be external documentation pushing that. Your code is in version control, but is your documentation under any kind of control at all?

    (Word + track changes? Hello 1997.)

    There should also be reports from your test system about dead code paths. But that is a whole other topic only appropriate for people who actually test their code. Being that is in general harder than writing the code itself...well, you can figure that quality disaster out yourself.

  88. Expiration dates by jlusk4 · · Score: 1

    Either date- or version-based. "Delete after dd-mmm-yyyy" or "Commented out in 5.1". (Note how cleverly I avoid anticipating future version numbers. Management tends to change those things.)

    To all the people saying "version control": I've seen enough botched configuration-management system changes and moronic branch management to know it ain't the be-all people think it is.

  89. Don't use code control for this by Anonymous Coward · · Score: 0

    I work with people who say the same thing- "delete stuff and depend on code control system to get it back if you need it. That's what it's there for." However, this doesn't work over a long period of time (many months to years). Sometimes trees get moved, and history gets lost. Or code control systems change, or filenames change or get deleted, which means you have to use special commands to resurrect the file from code control. I have seen the same problems crop up on different code control software.

    Due to the above, I like keeping deprecated code in a directory called "retired_code". I do this to have a reference to look back on, in case something was tricky to code, and because sometimes when I supposedly don't have to support something anymore management changes their minds, and I have to resurrect it. The size of the retired_code areas is nothing compared to the size of our trees, so disk space is not a concern. Also, I set my IDE to ignore any directories called "retired_code", so I don't get false hits when searching for things.

  90. Explain why it was removed by MobyDisk · · Score: 3, Insightful

    When removing code, consider commenting why it was removed. I've seen cases where code was removed then added back in causing bugs to reappear.

    Before:
    Log(“Shutting down”)
    CloseLog();
    Reboot();

    After:
    Log("Shutting down”)
    Reboot();

    Better:
    Log(“Shutting down”)
    // Don’t close the log file here because some other thread might still
    // write to it during shutdown/reboot, which could cause an error dialog
    // that prevents shutdown. The file will be closed anyway by the OS.
    Reboot();

    1. Re:Explain why it was removed by Anonymous Coward · · Score: 0

      Better:
      Log(“Shutting down”)
      // Don’t close the log file here because some other thread might still
      // write to it during shutdown/reboot, which could cause an error dialog
      // that prevents shutdown. The file will be closed anyway by the OS.
      Reboot();

      Even better:
      Log(“Shutting down”);
      // Don’t close the log file here because some other thread might still
      // write to it during shutdown/reboot, which could cause an error dialog
      // that prevents shutdown. The file will be closed anyway by the OS.
      Reboot();

    2. Re:Explain why it was removed by Anonymous Coward · · Score: 0

      In this hypothetical language, semicolons only go after Reboot statements. :-) Also, this language requires proper use of left and right quotation marks (for nesting).

  91. A news story about an article about a question by Anonymous Coward · · Score: 0

    I don't quite get how this qualifies as news. This story points toward arstechnica which basically just summarizes(wrongly) the question and answers from programmers.stackexchange... The actual question name was "Unwritten rules of rewriting another team member's code" and covered rewrites, not just plain deletion.

    1. Re:A news story about an article about a question by earlzdotnet · · Score: 1

      I don't quite get how this qualifies as news. This story points toward arstechnica which basically just summarizes(wrongly) the question and answers from programmers.stackexchange... The actual question name was "Unwritten rules of rewriting another team member's code" and covered rewrites, not just plain deletion.

      Whoops accidentally posted as AC. mehhh

  92. My 1st Rule by Anonymous Coward · · Score: 0

    Personally, my #1 rule for code deletion is:

    Comment code out frist, if the product gets released with the code block still commented out, then delete it.

  93. more important is the documentation by Anonymous Coward · · Score: 0

    I'm seeing a lot of people claiming source control and deleting is the way to go and others saying commenting out code for a few versions is better. Either is fine, but the important this is that the change is properly documented. Almost no one does this. If you comment out or erase a piece of code you could leave behind a comment explaining what was done and why. It drives me up the wall when I come across a line that has been commented out which no explanation given (either in the source or in the commit notes).

    Personally, I prefer the comment out for a few versions and then delete method. The reason being it is much easier to just glance at the code and (hopefully) its comment to see what was going on all in one place. I don't want to have to go looking for old code (and the reason it is not there anymore) in the source control. Better to have all the information, new and old, in one place. Just because source control allows you to backtrack doesn't make it the most appealing method.

  94. code block history by Immerman · · Score: 2

    So, when you realize a year and several thousand commits later that the rewrite neglected to handle a rare and complicated corner case, what's the easy way to find the previous version in the commit tree?

    That's a serious question by the way. I'm still fairly new to VCSs, but the one big lack I see (and it may just be to EasyMercurial's stripped-down gentle-intro interface) is there's no simple way to say "show me the history of this specific section of code". Now sure, in an ideal world the commit comments would let you immediately recognize the relevant commit when you saw it, but thats still be a lot of manual searching to do. If I remember correctly hg does have the ability to trace the history of a particular file, but there are plenty of situations where a file may have seen lots of changes for lots of different reasons. Is there any mechanism available to quickly pick out just the changes to, say, a particular function? Or really, even just list the relevant commits.

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
    1. Re:code block history by Nevynxxx · · Score: 1

      Have a look at DARCS ;)

    2. Re:code block history by Immerman · · Score: 1

      That does look like a fascinating project. Not sure I'm ready to make the jump to a whole different VCS though. I'm still acclimating myself to using one at all, and EasyMercurial's dirt-simple GUI lets me focus on the core functionality and easily visualize the history and branches, without having to remember specific commands. It doesn't sound like there's anything comparable for darcs (seriously - I even recommend EM to my non-techy friends for their computer-based projects. It's not as nearly as useful for non-text projects, but it's still a simple, powerful check-pointing tool).

      There's also the fact that I suspect the drastically different design philosophy would mean a lot of things wouldn't translate into the sorts of VCSs I'm likely to encounter professionally if I get back into the field. I decided to go with a DVCS since they look to be an unqualified improvement over the older, centralized approach, but still use basically the same metaphors so that I shouldn't have too much trouble adjusting to most any system I'm likely to encounter.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    3. Re:code block history by Anonymous Coward · · Score: 0

      I hear you on the line specific searching. SVN doesn't show that either.
      But your not really searching by line now. now you're searching by issue.
      you do have your issues linked to your commits, right?
      Finding a bug in line n (more practically in method n as 1000 commits later the line is arbitrary) means you can peruse the issues related to that file, get the general issue number related and then browse the code.
      My Jira/svn plugin makes that easy - hyperlink ing the list of files and versions related to an issue.
      In case the issue isn't available (mis logged or not searchable for some reason)

      Leaving commented code in because your afraid of losing it or forgetting something when you fixed it is just silly and messy.

      But with 1000 commits to one file in a year, you might have some other issues to sort out, like breaking up some functionality into delegates. That's an average of 3 commits a day to one file. It's overworked

    4. Re:code block history by Immerman · · Score: 1

      I quite agree that leaving in commented-out code is wasteful and distracting,especially since 90+% of the time you can just say "well it was working last month/year/whatever, I'll just do a diff to this file from some random commit from then and see how it was done". You always run the risk there of overlooking an intermediate bug fix though, and reintroducing something that had been fixed before some idiot nuked the whole thing though. It would be easy enough in principle to write a utility to go through all commits that touched the file in question looking for changes to a particular function, provided you were sufficiently competent in using the VCS and/or didn't care about performance, otherwise... well it just seems like the sort of utility that there'd be enough demand for that somebody has probably already made a better version than I could.

      As for 1000 commits a year - I admit I pulled numbers out of the air on that one, but I can easily make a dozen commits a day when working on particularly troublesome code, especially the sort that's trying to work around limitations in outside modules with lots of side effects (quite common when modding games, a hobby of mine. And I tend to push the limits of what's possible within the engine so stuff tends to break. A lot. ) Now in a properly disciplined environment the vast majority of those commits would never make it into the main branch... but I believe I mentioned I'm still just getting accustomed to using a VCS system at all :-) For now I'm trying to use the "commit early, commit often" approach and mostly neglecting a lot of the organizational niceties - and still sometimes forgetting to commit at all for extended periods.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
  95. Ask Slashdot by Fnord666 · · Score: 1

    How is this not an "Ask Slashdot" article?

    --
    'The tyrant will always find pretext for his tyranny.' - Aesop's Fables
  96. No Multiline /* . . . */ by tgeek · · Score: 1

    That's all I ask in regards to comments -- no /* . . . */ to comment out multiple lines of code. Nothing I hate worse than spotting something in code that piques my interest only to discover there's an open /* several lines above it (often times scrolled out of my window). So I make a point of ensuring that every comment is identified on each line (a complete /* . . . */ set, //, or whatever the particular language dictates). Only exception being multi-line text or narrative -- I have no problem with that being wrapped in /* . . . */.

    Yeah, yeah, I should use a better IDE that would identify all those lines as comments, but many times I'll be browsing code with nothing more than vi or grep.

    1. Re:No Multiline /* . . . */ by coolmadsi · · Score: 1

      That's all I ask in regards to comments -- no /* . . . */ to comment out multiple lines of code. Nothing I hate worse than spotting something in code that piques my interest only to discover there's an open /* several lines above it (often times scrolled out of my window). So I make a point of ensuring that every comment is identified on each line (a complete /* . . . */ set, //, or whatever the particular language dictates). Only exception being multi-line text or narrative -- I have no problem with that being wrapped in /* . . . */.

      Yeah, yeah, I should use a better IDE that would identify all those lines as comments, but many times I'll be browsing code with nothing more than vi or grep.

      I've seen the same issue using the diff tools in Version Control systems - there's no syntax highlighting there either.

  97. Old code is the comments by Anonymous Coward · · Score: 0

    1. Write the first version of the function to be simple, obvious, and portable, with no real consideration for speed.

    2. If necessary, write the second version of the function to use a more efficient algorithm, but leave the first version in comments as documentation for what the new version does. If you think you have a bug, you can test it against the first version.

    3. If necessary, write the third version of the function to use platform specific optimizations, in assembler, or whatever you want. Leave the second version in comments as documentation for what the new version does.

    Delete code when the functionality isn't needed. Never delete code because you've implemented the same functionality in a more clever way.
    When you change the structure of the code to make a more general function to handle multiple cases, write the first version in the simple, obvious way. If you decide the structural change isn't working, go back to an earlier version.

  98. The first rule of Code Deletion is... by Anonymous Coward · · Score: 0

    You do NOT talk about code deletion!

  99. Does is pass regression with the code deleted? by dbc · · Score: 1

    If you have version control, and yet still fear deleting code, then methinks your regression suite and code review process are weak.

    Do you have a good handle on the coverage provided by your test suite? Is the code change, including the deletion, talked about during code review before your dev branch is merged into mainline? Does your defect tracking system allow you to tag defects with an 'incorrect deletion' marker? Are you adding a targeted test to the regression suite for every diagnosed defect?

    If 'yes' to all, then delete it and let version control keep the history for you.

  100. There is only one rule by edibobb · · Score: 1

    1. It's easier to write the second time.

  101. Don't hold back. by Anonymous Coward · · Score: 0

    Delete it all and let source control sort it out!

  102. Unwritten? by Anonymous Coward · · Score: 0

    WTF do you mean unwritten. The code conventions for your shop should cover it.

  103. Add Unit Test Cases by ZombieBraintrust · · Score: 1

    If your changing code because the old code had a bug then you need to add test cases to your test scripts. Add tests that reproduce the bug and fail in the old code. Add good comments to the test documenting what defect the test reproduce. Then if someone goes back and reverts the change in the source the test will fail.

    1. Re:Add Unit Test Cases by MobyDisk · · Score: 1

      This is a good point in general. But every time I ran the unit test it rebooted my computer. :-)

  104. The First Rule of Deleting Code... by whoisjoe · · Score: 1

    You don't talk about deleting code!

  105. The problem is... by jvkjvk · · Score: 1

    not that they are unwritten. There were detailed instructions on this topic.

    The problem is that the instructions were deleted before being implemented.

    A koan for a new age.

  106. Comment out for a while then delete, usually by cyberfunkr · · Score: 1

    Depending on what is being deleted, I flip-flop back and forth between commenting out chunks for a revision or two and then deleting, and just deleting. For small sections, I tend to just straight delete. In rare circumstances I'll delete but replace the code with a comment like "Used to do X here, but now it's covered by Y" but only until Y becomes the standard and then those tend to drop off.

    For larger sections or whole functions I tend to comment out first until I'm sure the new code is working then deleting it. There are a few reasons behind this:
    1) There is an advantage to having the old code instantly available (no diffs, no downloading to a separate directory, etc) to make sure that all the functionality that was previous there is still in the new code. It's very nice to go back and look when the new code isn't working right to flow through the old code and see what's missing. "Oh, we used to set this flag, but when I optimized I did away with it. Apparently, someone is using it much later in the code. Guess I need to put it back." *

    2) There is a standard of, when creating new database functions (a new table), that there be a set of default functions; Create the table, Load Defaults (if applicable), Insert a record, Update a record, Load a record, and Delete a record. But as time goes by developers may create more specialized versions of these functions (JOINing other key tables, for example). More updates and soon no one is using the regular functions as the specialized ones work for what they need and then some. So if I see a function not being used any more I comment it out saying, "Deprecated; try using FunctionName() instead." If nothing breaks immediately, and no one complains for a few revisions, the extra functions go away.

    * The better, but not real-world, solution would be contact whoever maintains the code that used the flag and see if we can they can update/optimize the code to work without the flag.

  107. Make sure you can un-un-delete it by davidwr · · Score: 1

    If you have a good source code management system, you should get this ability for free.

    If you don't and it's not a throwaway project, get one.

    If it is a throwaway project, then there probably aren't any rules.

    Once you know you can un-undelete it, the same rules apply as to adding or changing code:
    * Make sure your edit improves the code.
    * Don't introduce any bugs.
    * If you can't avoid the previous rule, don't introduce any important or subtle bugs. Especially don't introduce any important, subtle bugs.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  108. The unwritten rules of deleting code by Anonymous Coward · · Score: 0

    I am not sure I can write them down, what with Russels paradox.

  109. Re:Simple: Don't by viperidaenz · · Score: 1

    So now you have to go back "some time" in the future to clean up the mess you left the first time? Who's going to pay for the cleanup?

    Commits should be small and should only encompass a single bug or feature, which is logged in you bug tracking system. The commit should also be tagged with the bug id.

    Try and submit a patch with a bunch of commented out code to a major open source project and see if it gets accepted.

  110. Don't delete... by Anonymous Coward · · Score: 0

    ... and don't comment it out. Wrap the code in if(false) { ... }!

  111. The 1970s called and want their question back. by bregmata · · Score: 1

    Srsly guise, if you're asking this question, you're in the wrong field.

  112. The point why removing code is so hard by allo · · Score: 1

    The point why removing code is so hard is not, that its hard to restore. We have VCS for this.
    But its hard to discover, the code ever existed. Who goes to the VCS and searches for old commits, when implementing a new function? If you weren't there when the code were in use, its unlikely you find it in the VCS instead of rewriting it.
    So removing code is a decision about making it hard to find, that it ever existed.

    One solution would be to remove and leave a comment behind "here was code, which was removed in a commit at $DATE". What other solutions are there, for this dilemma?

  113. Re:Simple: Don't by asdf7890 · · Score: 1

    So now you have to go back "some time" in the future to clean up the mess you left the first time? Who's going to pay for the cleanup?

    By "some time" I'm meaning days or weeks, not many months or more.

    Slap everything commented that doesn't need to persist with a "CLEANUP" tag and scan for them pre-release or at then end of a run of sprints (and/or as you approach a release, where-ever it fits in your flow) as part of your other housekeeping tasks. Give the job to a junior so he/she might learn from the changes (have a more experienced dev to hand in case of questions, and to try make sure the wrong things are not learnt from less "clean" work).

    Try and submit a patch with a bunch of commented out code to a major open source project and see if it gets accepted.

    Each open source project will their own preferences and rules which are fine by me, but equally are not my problem currently (if I were to have something to contribute I'd would of course try to fit into the project's preferred coding standards (or just release my changes as-is and if anyone else wants to clean them up and claim the credit they can go right ahead, if not then fair enough too)).

  114. rm-rf/*.* by Anonymous Coward · · Score: 0

    Watch this post disappear and don't forget var/logs on your way out of the door.

  115. Only one rule by TheSkepticalOptimist · · Score: 1

    Having JUST gone through this the only rule about deleting code is to NOT delete code someone is actively working on just because you don't understand or like it. I had about 3 weeks of work blown away by a "senior" developer who didn't understand or like what I was doing, deemed it unnecessary, and nuked it in a single check-in even though I am actively working on it without even consulting me.

    Rule #1: Ask yourself, "Am I being an asshole if I remove this code?" If the answer is yes then don't do it.

    --
    I haven't thought of anything clever to put here, but then again most of you haven't either.