CodeSOD: Switched Over |
Twelve years ago, a company decided they needed a website. They didnt have any web developers, and they didnt 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;
}
Theres 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 dont exist in a function, either- theyre slapped right into the global namespace.
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |