Article 5F3QV CodeSOD: Leave Some Comments Behind

CodeSOD: Leave Some Comments Behind

by
Remy Porter
from The Daily WTF on (#5F3QV)

We have a lot of stories about the code coming from offshore/outsourced developers being of low quality. Today, Radu S sends us the reverse. He used to work for one of those offshore development shops. A customer started development in-house, and then decided that they didn't want to support their own code anymore, and shipped it off to Radu's company.

This block represents what he's working with:

//if-else put here. Sometimes Querystring[2] is needed.//other times it is QueryString[0]. Not sure why...//John Doe 01/04/16//eliminated if-then-else because of problems toggling between//radio buttons//John Doe 09/29/16string nguid;//if (Request.QueryString.Count == 1)//{ //nguid = Request.QueryString[0]; nguid = Request.QueryString[1];//}//else//{// nguid = Request.QueryString[2];//}

Radu found this block because there were seemingly random errors showing up, depending on how the user navigated through the application. And it's easy to understand why: "John Doe" was attempting to access query-string parameters by position, which is in no way, shape, or form guaranteed by their front-end. So this code never worked reliably, but could easily be fixed by changing it to be nguid = Request.QueryString["nguid"].

That's mildly ugly, but the misuse of source-control gives us the rare insight into the developer's thought process. They could see that something was wrong, but couldn't figure out what that was. They experimented with conditional blocks to work based on the count, but never reached the point where they checked the documentation for Request.QueryString, or perhaps more specifically, the NameValueCollection that property returns.

It's no surprise that the customer no longer wanted to support this in-house.

proget-icon.png [Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more. TheDailyWtf?d=yIl2AUoC8zAR653CaaB2l0
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments