7 ms·
I've done something like that too. I also noticed that enums are even lower-friction (or were, back in 2014) if your IDs are integers, but I never put this patt
by default-kramer 1y ago
I've done something like that too. I also noticed that enums are even lower-friction (or were, back in 2014) if your IDs are integers, but I never put this pattern into real code because I figured it might be too confusing: https://softwareengineering.stackexchange.com/questions/309081/what-are-the-drawbacks-to-mapping-integral-identifiers-to-enums https://softwareengineering.stackexchange.com/questions/3090...
- gpderetta 1y agoFWIW, I extensively use strong enums in C++[1] for exactly this reason and they are a cheap simple way to add strongly typed ids. [1] enum class from C++11, classic enums have too many implicit conversions to be of any use.
- TuxSH 1y ago> classic enums have too many implicit conversions They're fairly useful still (and since C++11 you can specify their underlying type), you can use them as namespaced macro definitions
- TuxSH 1y ago> classic enums have too many implicit conversions They're fairly useful still (and since C++11 you can specify their underlying type), you can use them as namespaced macro definitions Kinda hard to do "bitfield enums" with enum class
- gpderetta 1y agoit is not really hard, you need to define the bitwise operators. It would be nice if they could be defaulted.