Fog Creek Software
Discussion Board




Large blocks of code commented out in Source Ctrl

I have asked my co-workers a few times not submit code to Perforce with large blocks of code commented out instead of just removing the offending code.

Unless it's temporary and there's a nice big note on top saying why it's being done...this should be rare though.

I find large blocks of commented out code to be ugly. I also think it causes problems later on down the road because you can't remember why this big ugly blob of code is staring you in the face three months later.

This is what source control is for.  Is anyone in disagreement?  Anyone got any other reasons to add to why this shouldn't be done?

BTW, these are not 10 million line C++ monsters, this is VB6 and ASP.  Small projects, nothing more than 30,000 lines

Wayne
Thursday, May 20, 2004

It probably needs to be refactored.

Derek
Thursday, May 20, 2004

As a rule I never delete lines while making changes, I just comment them out.  I will delete any older lines commented out during a previous change if I am doing further changes.

Couple reasons:

- while in development mode - I find it much easier to restore a piece of code that I commented out earlier - which happens often enough

- Real easy to see what the last change was without having to go back to the source control - great for debugging after it has gone out to production.

YMMV

DJ
Thursday, May 20, 2004

DJ, you're probably talking about the very early stages of development. After it's in production release, all that junk should be out because you should assume it's going to be read by and tested by someone else (i.e. QA if there is such an animal). Code with snippets of past trials and errors becomes cluttered and unreadable.

old_timer
Thursday, May 20, 2004

I agree with Wayne.  That's one of the reasons we use source control.  If you want that code, go back to an old revision.

christopher baus (www.baus.net)
Thursday, May 20, 2004

... or comments shouldn't hold revisions of your source.

christopher baus (www.baus.net)
Thursday, May 20, 2004

We usually leave them in for a while.  The reason is a customer changes their mind often enough that restoring it is a lot easier. 

As for source control, that works great if a module gets changed once every "n" changes.  If it is repeated changed then just "restoring" to an older version is not going to work. 

1 man's opinion, shared by many....

Anonanonanon
Thursday, May 20, 2004

95% of the time I delete rather than comment out code. I personally find it very distracting especially when it interferes with folding code. However, 5% of the time I'll comment out code and say if this is still here X days from the date I commented it out then delete and of course I say why I commented it out with an indication why I did not delete. I'm with OP, we have source control so the rare time I don't delete is when ... heck I can't think of a good reason. 

me
Thursday, May 20, 2004

exactly: it's a phase out. disable code somehow, then a bit later remove it.

perhaps a comment is a good idea, to make sure the second phase happens.
// following block removed on 5/20/04 because the frobinator is used instead. if it's still not needed in a month, delete it.

mb
Thursday, May 20, 2004

While I'm testing the impact of my source change I keep the source commented out.

However before I check in the file I rip out all the commented code. As others have said -- if they want the code back they can look at the previous version(s).

BobRoss
Thursday, May 20, 2004

The problem with 'look at previous versions' is that a new developer may not know it existed. I feel it is unreasonable to expect the new guy to go through every revision and see what was changed.
I like to comment out, with a date and initials.
After 3 months, I will remove it, and leave the comment about what I removed, along with the original comments for why I commented it out. Usually with a 'bug' number.
This way a new programmer could see that there was code in there before, knows why it was changed. If the new code introduces a bug that isn't caught in QA, a new developer will at least know what was there, and will know where to look in the version control product.

Garrett
Thursday, May 20, 2004

Agree with Bob Ross and Wayne -- we've done it both ways, and found commented-out code just never got put back, plus eventually people couldn't remember why or who commented it out so it would never get deleted.

As far as new programmers joining the project then somehow deciding to re-do previously commented-out code (not knowing it was in previous check-ins), that's just never happened in my experience. Better to keep things clean and simple...

Ron
Thursday, May 20, 2004

I also vote for deleting the unneeded code. 

If you are going to leave it in put a comment indicator on every line or use a syntax coding editor. It is very frustrating to try and debug some code and finally realize that you are looking at a section that was commented out three pages earlier.

john
Thursday, May 20, 2004

Also, since the comment-out code isn't run, tested, or even compiled, it stops working when you change the rest of your code base. Besides, how often have you restored commented-out code?

Julian
Friday, May 21, 2004

It depends on the model of source control you're using.

Do you expect the tip to always work, or do you use the tip to experiment and use branches for freezes?  Expecting the tip to be gold (or at least silver) all the time either means the developer should have their own branch or they keep their changes in their head;commented out blocks;alternate trees on their machine;an entirely different source control system.

In all those latter cases (examples of all of them I've seen and even done in the past), source control was a group god that everyone believed in but didn't pray to.

Simon Lucy
Friday, May 21, 2004

Simon, that was all way above my head.  I work at very a small shop here and we have use only the most basic abilities of our source control software.

The latest revision of everything is supposed to be what works.

Wayne
Friday, May 21, 2004

Delete the old code. Don't comment.


Friday, May 21, 2004

It seems to me that the ultimate goal of "literate programming" is to compile only the comments!

You really should read about CWeb, Leo, etc. to see what I mean.

Data Miner
Saturday, May 22, 2004

Hmm....

We had this "problem" with the senior developer in our team. He would leave pages and pages of commented-out  code behind.

So we convinced him to date the commented blocks, and after 3 months, without side-effects, we could delete them.

Works like a charm.

emp
Monday, May 24, 2004

*  Recent Topics

*  Fog Creek Home