Article 2RFMN CodeSOD: Switched Over

CodeSOD: Switched Over

by
Remy Porter
from The Daily WTF on (#2RFMN)

Twelve years ago, a company decided they needed a website. They didn't have any web developers, and they didn't want to hire any, so they threw a PHP manual at the new hire who happened to "be good with computers", and called it a day.

Ms. "Good With Computers" actually learned something from the experience, and moved on to a lucrative career in web development. Unfortunately, she left behind the code she learned by doing, and now Bert has been brought in to clean up the code.

Take this block, which translates an airport code into a location name"

 switch ($v) { case "EIN": $ori = "Eindhoven"; break; case "EIN": $ori = "Eindhoven"; break; case "EIN": $ori = "Eindhoven"; break; case "EIN": $ori = "Eindhoven"; break; case "EIN": $ori = "Eindhoven"; break; case "EIN": $ori = "Eindhoven"; break; default: break; } switch ($b) { case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; case "WRO": $des = "Wroclaw"; break; default: break; }

There's hundreds of lines of this, following the same pattern- one switch block with the same condition repeated many times for each possible airport code. These blocks don't exist in a function, either- they're slapped right into the global namespace.

otter-icon.png [Advertisement] Otter enables DevOps best practices by providing a visual, dynamic, and intuitive UI that shows, at-a-glance, the configuration state of all your servers. Find out more and download today! TheDailyWtf?d=yIl2AUoC8zApNEe0Ef-iJ8
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