Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

A lot of the code I've been working on recently, both professionally (read: at work) and in other spheres (read: at home, for friends/family/etc, or NOT FOR WORK), has been worked on, redesigned and re-implemented several times - where possible/required. This has been in an effort to make things smaller, faster more efficient, better and closer to spec (when requirements have changed).

A down side to this is that I now have several code bases that have deprecated method blocks (and in some places small objects). I'm looking at making this code maintainable and easy to roll back on changes. I'm already using version control software in both instances, but I'm left wondering if there are any specific techniques that have been used by others for keeping the superseded methods without increasing the size of compiled outputs?

At the minute, I'm simply wrapping the old code in C style multi line comments.

Here's an example of what I mean (C style, psuedo-code):

void main ()
{
  //Do some work
  //Foo();  //Deprecated method call
  Bar();    //New method
}

/***** Deprecated code *****
/// Summary of Method
void Foo()
{
  //Do some work
}
***** Deprecated Code *****/

/// Summary of method
void Bar()
{
  //Do some work
}

I've added a C style example, simply because I'm more confident with the C style languages. I'm trying to put this question across as language agnostic (hence the tag), and would prefer language agnostic answers, if possible - since I see this question as more of a techniques and design question.

I'd like to keep the old methods and blocks for a bunch of reasons, chief amongst them being the ability to quickly restore an older working method in the case of some tests failing, or some unforeseen circumstance.

Is there a better way to do this (that multi line comments)? Are there any tools that will allow me to store these old methods in separate files? Is that even a good idea?

share|improve this question
    
.NET languages have the ObsoleteAttribute for this exact functionality - the compiler will output warnings for any code using an obsolete method. –  Oded Apr 3 '12 at 15:18
add comment

2 Answers

up vote 8 down vote accepted

Is there a better way to do this (that multi line comments)? Are there any tools that will allow me to store these old methods in separate files? Is that even a good idea?

You should track and remove all commented code block. You are already using versioning, so the old code will be available whenever you feel nostalgic or if you have broken something while refactoring.

Commented code is just useless clutter.

share|improve this answer
    
The author stated I'm already using version control software in both instances, so setting up another won't help much. I agree though. Keep them in previous revisions and don't worry about the current one. –  Dylan Yaga Apr 3 '12 at 15:23
    
@DylanYaga yes, I have edited my answer. Good news is: he just has to start using it! –  Simon Apr 3 '12 at 15:24
    
I thought that this was the way to go, but I wasn't sure if there where any (for want of a better phrase) other ways to do this. –  Jamie Taylor Apr 3 '12 at 15:25
    
There's no benefit to keeping it, and no cost to removing it (if it really is obsolete). So, why keep it? To paraphrase some artist dude whose name I can never remember: your program is done not when there is no more code to add, but when there is no more code to take away. –  Tacroy Apr 3 '12 at 16:45
add comment

Source control is fine for this. You don't need to leave your code base cluttered up with old methods/classes that shouldn't be used.

Tag or branch at any milestone.

You can get back to any "last working copy" you like this way.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.