4 ms·
> The one tiny drawback is that the globals have to be variables instead of constants, but that’s one of those problems that really only exists in the theoretic
by henvic 4y ago
> The one tiny drawback is that the globals have to be variables instead of constants, but that’s one of those problems that really only exists in the theoretical realm.
I'd argue that needing this enums safety so bad that you go out of your way to create a struct with a protected field also lies in the same category of something you need that is mostly in the theoretical realm too.
Don't get me wrong, sometimes you want that kind of protection indeed and it's easy to mess up if you need to add validation everywhere. However, most times you can get away with just rethinking your code.
More importantly, I think the downside of using variables rather than constants makes it less safe than the alternative of relying on you always having to do validation.
- vlunkr 4y agoI had the same thought. You're just swapping one non-issue for another.
- tedunangst 4y agoThe alternative of using plain strings is prone to typos, which variable names are not (or less so).
- henvic 4y agouh? I'm saying "just use regular constants". The risk of typos is when you're defining them, just as much as the risk of defining bad variable values.