4 ms·
If Rust wants to win C/C++ developers, it shouldn't surprise them a lot.
by halayli 11y ago
If Rust wants to win C/C++ developers, it shouldn't surprise them a lot.
- kinghajj 11y agoWell it shouldn't be surprising, as Rust's enum behaves pretty much like a C/C++ one if all cases are nullary. The only changes are syntactical ("EnumType::Variant" instead of just "Variant", unless you "use EnumType::*"). In fact, it's exactly because they didn't want to be surprising that they used "enum" instead of something else, like "data" in Haskell.
- barosl 11y agoI would say that the reason it is named `enum` is exactly not to surprise them. While learning Haskell, I had used `data` several times, but never grokked its true meaning. The naming of `enum` in Rust helped me finally understand what ADTs are, and thus also made me truly understand what Haskell's `data` is. I really appreciate Rust for trying to introduce a certain concept with the existing names.
- Dewie3 11y agoThey already chose to try to appeal to those developers by calling it "enum". And that doesn't sound like a good motivation to me: how hard is it to learn something like algebraic data types, compared to learning about lifetimes? It's like the choice to use angle brackets for generics - if the intent is to be easy for programmers with a certain background, that only lures them in with a false sense of familiarity. Because something like angle brackets over square brackets is, again, a superficial and easy thing to learn compared to any of the semantic stuff.