Wandering Thoughts archives

2011-09-20

Why I still comment out code even with a VCS

One of the bits of VCS doctrine that I've seen is that once you have a VCS you shouldn't comment out code (or #ifdef it out or the equivalent); instead you should just delete it because you can always get it back from the VCS.

Well, I have a VCS or two and I have to say that I continue to comment out my code for the most pragmatic of reasons: I find it an easier way to work. In theory the whole idea of using the VCS for this is great, but in practice, well, it's got some drawbacks. First off, at least in my straightforward environment I haven't seen a really convenient way to revert parts of changes; it's not as if I can open up an older version of the file in another editor buffer to cut and paste back and forth. Plus there's the problem of finding whichever old version of the file that has whatever bit of code that I want to look at or get back. If I keep code commented out or disabled but still in the current version, it's simply much more accessible than if it was marooned back in the version history.

(This is where someone tells me that GNU Emacs can do this with a suitably superintelligent mode.)

Another thing I like to do is to take two different versions of the code and flip back and forth between which one of them I'm running. If I do this with comments, I can flip versions without leaving my editor (sometimes I can do it with plain undo). This is important, since I have my editor open on the files all the time when I'm working (whatever my editor of the moment is); the last thing I want is to have to close down file buffers and then reopen them every time I want to do this sort of back and forth shuffle. Even if I'm not actively testing different versions, not infrequently I'm considering which version I like better and so I really want to see them side by side (well, one after the other).

Having said all that, I do follow the VCS doctrine to the extent that I try to delete old commented out code once I've reached a definitive stopping point and I'm confidant that the old code really is dead and is never going to come back. But I consider this more or less like cleaning up any other sort of comments in the code (which is something I try to do every so often, especially at the end of a burst of development).

programming/CommentingOutCode written at 01:22:08; Add Comment


Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.