3 ms·
> OTOH, an enum that appears often in conditionals is likely to be error prone and classes or interfaces should be considered instead. That's surprising. Isn't
by Zababa 5y ago
> OTOH, an enum that appears often in conditionals is likely to be error prone and classes or interfaces should be considered instead.
That's surprising. Isn't the whole point of an enum to switch/match on it?
> The question is: which approach creates more coupling and/or requires more points in the code to be updated to remain correct when a new value is added?
As other people mentioned when talking about the expression problem (https://news.ycombinator.com/item?id=29306511 https://news.ycombinator.com/item?id=29306511), it depends. If you're going to add new types, enums are better. If you're going to add new operations, polymorphic objects are better. If you're going to add both, hope that you're doing Clojure or Haskell.