As a general rule, “dead code” should never be commented out, but instead, should be replaced. If you ever need to review the history, source control contains that information.

But sometimes, the “I’ll just comment it out” lets us see the moment of realization, when a developer discovers that they’ve done the absolute wrong thing. Clara sends us this:

//HttpPostedFile file = Page.Request.Files["ctl00$phMainContent$fulProfileImage"];
//if (file != null && file.ContentLength > 0)
//{
// try
// {
//  string[] filenameparts = Page.Request.Files["ctl00$phMainContent$fulProfileImage"].FileName.Split('.');
//  byte[] fileData;

//  using (BinaryReader br = new BinaryReader(Page.Request.Files["ctl00$phMainContent$fulProfileImage"].InputStream))
//  {
//      byte[] imageData = br.ReadBytes(Page.Request.Files["ctl00$phMainContent$fulProfileImage"].ContentLength);
//      fileData = CreateThumbnail(imageData, 400.0f, 400.0f);
//  }

//  dealerEntity.ProfileImage = fileData;
// }
// catch { }
//}
if(fulProfileImage.HasFile)
{
    try
    {
        dealerEntity.ProfileImage = CreateThumbnail(fulProfileImage.FileBytes, 400.0f, 400.0f);
    }
    catch{
        throw;
    }
}

It’s a beautiful little collection of ignorance, a willingness to do it the hardware, and one of my favorite anti-patterns: swallowing exceptions. The important thing is that the developer clearly learned from their mistakes- or somebody who knew better came through and fixed it. Either way, the real lesson is use source control and don't comment out dead code!

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!