-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible enum
improvements
#14
Comments
Well, this is in a way, inspired by the C language where enums are nothing but (usually auto assigned) numerical values. At least that's how they are designed for Feral. I'd definitely like to know the benefits of printing enums as strings though 🤔 |
Also, one thing that can be, perhaps, done is that we can have something like
That being said, I'd still like to know the advantage of this concept with regards to enums (and their usage) 😄. |
Well, for starters, C enums are a bit broken IMO. I largely prefer C++ enum classes, which are more strict by default (you have to static_cast your way to do unsafe stuff). Regarding the string part, it would be mostly for introspection. e.g. to print all possible values to the user or finding the corresponding enumerator to a user input. Let's say you parse a configuration file where one field corresponds to an enum. Right now you either have to take numerical values (which is unsafe) or a string an maintaining a map between strings and enumerators (which is not very practical). Having a way to iterate over the enumerators and accessing their numerical value or their name would be great for these situations. Concerning the assignment from an integer, I get it but I would prefer it to be explicit (as with static_cast) but that's maybe because I'm more into statically typed languages than dynamic ones. |
That is a good idea. I'll think of something about it perhaps 🤔 |
Take your time for this, it's not like there is an urgent need for this |
Haha, thanks 😄 |
After playing a bit with
enum
s I can see two possible improvements:str()
function on an enumerator returns its numerical value instead of its name, which would be less confusingenum
's enumerators can be assigned, leading to an inconsistent stateExamples:
I still don't know enough about the internals of the language to know how to fix this, so I prefer create an issue
The text was updated successfully, but these errors were encountered: