----- "Larry Garfield" <larry@garfieldtech.com> wrote:
I have an irrational hatred of switch statements, so eliminating hooks that are nothing but nested switch statements half the time gets a big +1 from me. :-)
I avoid them, too. But I have what I consider rational reasons: * Converting switch statements into more complex conditions is difficult. They require refactoring, which is often a source for errors. If I use if/else, then I only have to worry about refactoring if the logic structure truly changes. Anticipation of change is the same reason we require braces for even one-line conditionals: expanding a one-line conditional that lacks braces is more error-prone. * Lack of break statements is a common source for errors. * With a combination of break statements and fall-through switches (intentional lack of breaks between cases), it can be difficult to quickly understand control flow. Unlike for if/else structures, control does not follow indentation. * A long series of cases is often justification for reconsidering the program structure, like we are right now with $op. Frankly, the best thing switch has going for it is rather simple conversion to assembly in lower-level languages like C++. The switch functionality is directly derived from "branch if equal" instructions, and break is directly derived from "branch unconditional" instructions.