Discussing the nuts and bolts of software development

Thursday, July 17, 2008


Maintenance Nightmares: Commented out code

I was working on an estimate for a prospective customer, and luckily I had the code to examine beforehand to see what it was doing.

While examining the code, I noticed code like this:

// Fix for bug 1021892
// some code that was commented out.

There were instances of this throughout the code.

When I see this I instinctively cringe, I immediately think that there is no proper source control or defect tracking procedures (or tools) in place. While there may be the odd corner case where commented out code is acceptable, in general it is not and should be avoided.

There are many better ways of dealing with this, the first way is to just delete the line of code, and when you commit/check-in the code, make sure you put a meaningful comment in the commit logs that ties it to the defect it was changed for. You can often search the commit logs, and if you put the bug id in the commit log, you will get the change in your search.

Another easy way to do this is to delete the line of code, make a patch, and when resolving the bug in your bug tracking software, attach the patch file to that issue. Then you can always see what you changed to fix the bug.

Does anyone else having any suggestions for this?


I think placing comments about the deleted code in the commit logs or patch's change log is the best way to deal with this kind of problem. Sometimes it is also possible to write done little explanation comments in the code, but just commenting out the code which should be deleted is not a good practice.
Not that I want to one-up you on this but I have been doing work with a popular ASP.Net component library.

With that library, when you buy a certain level of license, you get the source. I looked in there and is was scary. They seem to be doing version control with #ifdef statements.

The code is littered with #if V3.2 type of statements. I wonder if they ever heard of branching?
That is so crazy, I still can't believe that. Whoever did that deserves a special place reserved for them in the customer support section :)
You can always order your paper here https://paperovernight.com/blog/five-page-paper. This is very handy!

Thanks for your post!

شركة شحن عفش من جدة الى الامارات شركة شحن عفش من جدة الى الامارات
شركة شحن عفش من جدة الى الاردن شركة شحن عفش من جدة الى الاردن

Looking for a finance homework writing service in the USA? Look no further than 123Homework.com! We offer a wide range of services to help you with your finance homework, including essay writing, term paper writing, case study writing, and more. We have a team of experienced writers who are experts in the field of finance, and we can help you get the grades you need. Contact us today to learn more about our services!
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?