← Back to context

Comment by nawgz

5 years ago

I mean, hilarious point, but I'm not sure it's valid. Clearly he's numbering things here, but I am guessing in the real world you're far likelier to see tests of typing or some not-numerically-indexed value rather than literally numbered ENUMs

This can happen with any enum to function mapping. You cut and paste and forget to change one or the other.

In C, you could use a macro in this call to make sure that the name/number is only specified once.

  • I mean, this can happen with any code by that logic if you're cut and pasting.

    I think the real issue is types aren't included in the example. I work in much higher-level languages, but if you are passing strongly typed objects thru and your switch is derived on this typing, it's probably going to be illegal in your type system to return certain results.

    If your type system doesn't validate your results, then you'll be prone to the class of error you are discussing. Maybe that's common in C.