Auto enumeration
Community Forums/Monkey2 Talk/Auto enumeration
| ||
Would be nice if you could just pop in some way to auto define unique numbers for a group of constants. I think enumeration is the correct name for it but not sure. I have source files with nothing but a long list of constants (for logic states), It would be a nice touch if I did not need to define each value myself, all I care is that each number is unique. As game logic often uses states, this would seem like a nice fit for the language. I guess this could be handled by the pre compiler. |
| ||
This could be very useful. Something like:Enum IDLE, PATROL, ATTACK, GUARD EndEnum Or we could even have named enums, and use them as a type instead of 'Int', but just having the former would be enough for me (and also being able to hard code values within the enum). |
| ||
Enums would be nice. Auto-enums I could live without, but combined with the Structs that mark proposed in another thread, having Enums seems like it would be nice, too. The only part that concerns me would be that he mentioned structs may end up needing to be initialized.... |
| ||
I would love to have them too. |
| ||
Mentions enums here I don't know if auto-enums is planned but I agree it is nice sometimes you don't care what the generated number is.... http://www.monkey-x.com/Community/posts.php?topic=9711&post=102420 |
| ||
Enum MONITOR_DPI_TYPE MDT_Effective_DPI = 0 MDT_Angular_DPI = 1 MDT_Raw_DPI = 2 MDT_Default = MDT_Effective_DPI End Enum Of course my example was not the best choice. It's declared like this by Microsoft, see MSDN: MONITOR_DPI_TYPE enumeration. The following would be the same: Enum MONITOR_DPI_TYPE MDT_Effective_DPI MDT_Angular_DPI MDT_Raw_DPI MDT_Default = MDT_Effective_DPI End Enum Maybe enums could have a start value: Enum MyEnum 1 a b c End And a step value: Enum MyEnum 10 Step 2 a ' 10 b ' 12 c ' 14 End Also enums are often used with bit flags: Enum MyEnum a = (1 << 0) b = (1 << 1) c = (1 << 2) End Maybe that could be automated somehow, like: Enum MyEnum Binary a ' (1 << 0) b ' (1 << 1) c ' (1 << 2) End |
| ||
Enums - most definitely, yes! Though given the rationale for enumerated types: http://en.wikipedia.org/wiki/Enumerated_type#Rationale I think programmer assigned values should be forbidden. |
| ||
impixi wrote: I think programmer assigned values should be forbidden. I think it's better to be C/C++ compatible for importing C/C++ libs that often make use of it. - WMT_CODEC_INFO_TYPE enumeration - WM_AETYPE enumeration - WMT_VERSION enumeration - MONITOR_DPI_TYPE enumeration - http://en.wikipedia.org/wiki/Enumerated_type#C_and_syntactically_similar_languages - https://msdn.microsoft.com/de-de/library/2dzy4k6e(v=vs.90).aspx Any enumerator in the list, including the first one, can be initialized to a value other than its default value. Suppose the declaration of Suit had been the following: enum Suit { Diamonds = 5, Hearts, Clubs = 4, Spades }; Then the values of Diamonds, Hearts, Clubs, and Spades would have been 5, 6, 4, and 5, respectively. Note that 5 is used more than once. The value can be any constant expression, including use of Macros in C++. |
| ||
Sure, that's a good point. Personally, in other languages, I've coded specific values for enumeration labels (eg JANUARY = 1), but the purists could argue (probably correctly) that by doing so I've violated an architectural paradigm somewhere. I suppose the point is that if the programmer needs to assign a specific value to a specific label then he/she is not properly using enumerated values and some other structure is more suited to the task? |