Article 410G5 CodeSOD: A Load of ProductCodes

CodeSOD: A Load of ProductCodes

by
Remy Porter
from The Daily WTF on (#410G5)

"Hey, Kim H, can you sit in on a tech-screen for a new hire?"

The Big Boss had a candidate they wanted hired, but before the hiring could actually happen, a token screening process needed to happen. Kim and a few other staffers were pulled in to screen the candidate, and the screen turned into a Blue Screen, because the candidate crashed hard. Everyone in the room gave them a thumbs down, and passed their report up the chain to the Big Boss.

The Big Boss ignored their comments and hired the candidate anyway. A week later, this ended up in source control:

public static ProductCodeModel GetProductCode(int id) { for (int i = 0; i < GetProductCodes().size(); i++){ if(i==id) return GetProductCodes().get(i); } return null;}

Obviously, the loop is unnecessary. The real kicker is that GetProductCodes loads its data out of a file each time it's called. It contains thousands of lines, which means to access any individual product, the entire file has to be read into memory, id times, and if it's the last product code in the datafile, you have read the file N times.

proget-icon.png [Advertisement] ProGet can centralize your organization's software applications and components to provide uniform access to developers and servers. Check it out! TheDailyWtf?d=yIl2AUoC8zAuds9qUnyog4
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