CodeSOD: Mistakes Were Made
by Remy Porter from The Daily WTF on (#CZKP)
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] Use NuGet or npm? Check out ProGet, the easy-to-use package repository that lets you host and manage your own personal or enterprise-wide NuGet feeds and npm repositories. It's got an impressively-featured free edition, too!