5 ms·
How the fuck do you release a language without enums?
by mark38848 2y ago
How the fuck do you release a language without enums?
- sethammons 2y agoCan someone help me understand why enums are needed? They only seem like sugar for reducing a few lines while writing. What cannot be achieved without them or what is really a pain point they solve? Maybe it is hard to have a constant with type information?
- brainzap 2y agoThe original enum are just enumerated integer constants. What people want "the ability to express enums with an associated value", I think we should invent a new term.
- masterj 2y agoThe term you're looking for is ADT - Algebraic Data Types https://en.wikipedia.org/wiki/Algebraic_data_type https://en.wikipedia.org/wiki/Algebraic_data_type
- randomdata 2y agoWe did: Sum types.
- bouncycastle 2y agobecause you can just declare a custom type and have constants that use the custom type.
- hpeter 2y agoYou can enumerate constants. There is syntax to implicitly assign the integer values, just use iota as a value.
- Too 2y agoTo be honest I haven’t seen a single programming language that has decent enums. With that I mean fundamental and fool proof functions for to/from a string, to/from an int, exhaustive switch cases, pattern matching, enumerating. Seems like something that wouldn’t be too hard but everybody always fails on something.
- randomdata 2y ago> I haven’t seen a single programming language that has decent enums. There's not much you can do with an enumeration. It's just something that counts one-by-one. A useful tool when you have a large set of constants that you want to number, without having to manually sit there 0, 1, 2, 3... But that's the extent of what it can offer. > With that I mean fundamental and fool proof functions for to/from a string, to/from an int, exhaustive switch cases, pattern matching, enumerating. While a programming language may expose this kind of functionality, none of these are properties of enums. They are completely separate features. Which you recognize, given that you are able to refer to them by name. Calling these enums is like calling if statements functions because if statements may be layered with functions.
- randomdata 2y agoYou'll have to ask the Rust community. Rust lacks enums. Go, however, most definitely has enums (and exceptions too!). type E int const ( A E = iota B C ) It's funny how people who have clearly never even looked at Go continually think they are experts in it. What causes this strange phenomena?
- jjice 2y agoGo has a way to implement enums - I'll give you that. Rust does have enums though: https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html They can have values like sum types, or not.
- randomdata 2y ago> Rust does have enums though It does not. You'll notice that if you read through your link. A tag-only union is not the same thing, even if you can find some passing similarities. If you mean it has enums like the Democratic People's Republic of Korea has a democracy, then sure, it does have enums in that sense. I'm not sure that gives us anything meaningful, though. If we're being honest, sum types are the better solution. Enums are hack for type systems that are too limited for anything else. They are not a feature you would add if you already have a sufficient type system. It's not clear why Rust even wants to associate itself with the hack that are enums, but your link shows that its author has a fundamental misunderstanding of what enums even are, so it may be down to that. To be fair, Swift made the same mistake, but later acknowledged it. It is interesting that Rust has chosen to double down instead.
- jjice 2y ago> A tag-only union is not the same thing, even if you can find some passing similarities Why not? Seems to function the same way.
- randomdata 2y ago