3 ms·
Wouldn't dictionaries be a better option than union types? Union types seem to be for heterogeneous types, but Select boxes are homogeneous. Dictionaries are ke
by dexwiz 10y ago
Wouldn't dictionaries be a better option than union types? Union types seem to be for heterogeneous types, but Select boxes are homogeneous. Dictionaries are key/value stores with multiple named values per key, and they can be iterated. Sounds perfect for the usecase.
So two red flags. Author wanted to replace an existing tech with another buzzword tech he has never worked with. And the author immediately choose the wrong data type, likely because it was different.
I do agree though, if a web framework cannot easily do forms, its not very useful.
- ufo 10y agoI think in this case it boils down to whether you ever need to do a pattern match over the select box type. If you do, then having the compiler check for exaustiveness makes the code more robust. If all you care is the string representation of the strings and how they convert to a numeric time then a dictionary will do the job just as well, while keeping things simpler.