Forgot your password?
typodupeerror
Programming

What Are the Unwritten Rules of Deleting Code? 384

Posted by samzenpus
from the best-practices dept.
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?"
This discussion has been archived. No new comments can be posted.

What Are the Unwritten Rules of Deleting Code?

Comments Filter:
  • by Marillion (33728) <ericbardesNO@SPAMgmail.com> on Monday January 07, 2013 @03:08AM (#42502003)
    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.
  • Re:How can ... (Score:5, Informative)

    by ChunderDownunder (709234) on Monday January 07, 2013 @03:10AM (#42502015)

    version control.

  • Source control (Score:5, Informative)

    by foniksonik (573572) on Monday January 07, 2013 @03:12AM (#42502021) Homepage Journal

    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.

  • Sigh (Score:2, Informative)

    by styrotech (136124) on Monday January 07, 2013 @03:20AM (#42502057)

    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?

  • Re:The more..... (Score:5, Informative)

    by rwven (663186) on Monday January 07, 2013 @03:33AM (#42502111)

    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.

  • Re:Vigil (Score:5, Informative)

    by rwaldin (318317) on Monday January 07, 2013 @03:59AM (#42502247)

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

    https://github.com/munificent/vigil [github.com]

    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.

  • by LordLucless (582312) on Monday January 07, 2013 @03:59AM (#42502251)

    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.

  • Re:The more..... (Score:4, Informative)

    by Anonymous Coward on Monday January 07, 2013 @07:02AM (#42503175)

    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.

  • Re:How can ... (Score:5, Informative)

    by VortexCortex (1117377) <(VortexCortex) ( ... -retrograde.com)> on Monday January 07, 2013 @08:07AM (#42503431)

    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!

Any sufficiently advanced technology is indistinguishable from a rigged demo. - Andy Finkel, computer guy

Working...