4 ms·
I use enums in C, too. And the problems with C enums that people complain about don't apply for me. That's not what I mean by "use of types". What I mean by it
by jstimpfle 6y ago
I use enums in C, too. And the problems with C enums that people complain about don't apply for me. That's not what I mean by "use of types". What I mean by it is significant "programming in type language" as opposed to "in code language". Programming in type language I find unappealing because it is very indirect, implicit, and typically achieves very little per line of code.
- deleted 6y ago[deleted]
- viraptor 6y ago> I use enums in C, too Enums in C are just ints with names. They're error prone and not type checked. You can always use 0 instead of a name and it will work. You can use TLSv2 instead of ExterminateHumans and it will also work. > What I mean by it is significant "programming in type language" as opposed to "in code language". I honestly don't understand what you mean by this.
- jstimpfle 6y ago> Enums in C are just ints with names. Yes, they are integers. You can do arithmetic with them, you can use them as bitmasks, or use sentinels instead, like -1. I like that.
- oblio 6y agoKeep in mind that just because you like something, doesn't make it good, and that's starting to get more and more important in these days where software is used for everything, including things really depend on.
- steveklabnik 6y agoOkay so, the issue here is that you two are speaking past each other. Enums in Rust are more than enums are in C. So this conversation is something like: Them: I like sandwiches. You: I get sandwiches from McDonalds, they're great. Them: Yes, but those are burgers. (The implication being that there are also other kinds of sandwiches.) You: Yes, burgers are good. You're not wrong, but you're kind of missing what they're saying. Enums in Rust can be like enums in C, but they can also be tagged unions. Furthermore, Rust won't automatically cast an enum to an int, so it is a bit harder to make mistakes, even if you're using the C-like ones. That's the advantages they're speaking about. Enums are good and useful in C, it's true. That's why Rust added stuff to make them even more useful.
- viraptor 6y agoYup, plus the other uses have their own implementation. If you're doing arithmetics, in rust you probably want a constant. If you want a bitmask, there's bitfield crate (or a struct/enum with bitwise ops implemented).