4 ms·
"Other" doesn't mean the same thing before and after Cola has been added. "Unknown" would be more accurate. My personal opinion would be to make the enum nulla
by dominicrose 2y ago
"Other" doesn't mean the same thing before and after Cola has been added.
"Unknown" would be more accurate.
My personal opinion would be to make the enum nullable and not add a fake value.
- mewpmewp2 2y agoBut null value seems to have the intent that it doesn't have category at all. So, let's say there's a function createFruit(fruitType: FruitTypeEnum); If it's null, it seems wrong since it seems to mean that you have a fruit without type. If it's unknown, then it might also be incorrect, since you very well know the type, it just isn't handled there. So I'm wondering if best might be something like Unhandled, Unspecified or Unlisted.
- dominicrose 2y agoI guess if you know the type but it's not in the enum, then you can save it somewhere else. If the enum changes afterwards, that data can be used to update the enum value.
- kstenerud 2y agoIt's not about "other" having a meaning unto itself; rather it's about having a placeholder in the enum "space" (for older languages that implement it as an integer) so that customers can introduce their own variants. My library would then happily accept any value passed in, but only act upon the enum values that the library itself specifies. The customer would be entirely responsible for making sure their own variants behave well. This is not a common thing to do, of course, but when your customers are clamoring for what would actually be a useful feature for your product, even this somewhat ugly hack is a lot better than saying "no".