Hello, gophers. Lately I've been working quite a bit with enums as I'm moving a C program I had to Go, so I wondered if there was any progress on enums proposals and realized that none of them get anywhere without breaking the Go1 compatibility.
I've decided to get a bit creative and share with you the proposals I've thought of. The fundamental thing when we talk about the incorporation of "robust enums" is, similarly to the case of generics, to propose a syntax extension to the language without breaking compatibility with the previous software. We use enumerations simply to handle states and encapsulate them under a name. Therefore I wanted to propose the following syntax: ```proposal const (<ENUM_TYPE>) <NAME> <TYPE> = <VALUE> ``` The idea of this syntax is that, roughly speaking, it reminds us of what we do when we declare a method, with the only difference that in this case we use constant values associated to some "enum type". Then, we should be able to call our constants as follows: <ENUM_TYPE>.<CONSTANT_NAME>, the same would be true for an already instantiated type. ```example type Statement struct{ /* ... */ } type StatementTyp int const (Statement) ( Prepared StatementTyp = iota Success Fail ) func main() { stmt := Statement{} fmt.Println(Statement.Prepared) // 0 fmt.Println(stmt.Success) // 1 } ``` Realistically speaking this doesn't solve much. It just gives us a way to encapsulate constants in an "elegant" way and keeps the "const-iota" syntax, but little else. I think it is essential to have an extra way to reference these internal values of a type so that we can work with the help of the go-typechecker. For this I could only come up with two types of syntax, let's see: ```prop1 var bar const <ENUM_TYPE> func foo(arg const <ENUM_TYPE>) {...} ``` ```prop2 var foo <ENUM_TYPE>.const func bar(arg <ENUM_TYPE>.const) ``` That would be all, I hope you can give some feedback and know what you think. I read in the go2-language-template <https://github.com/golang/proposal/blob/master/go2-language-changes.md> that it was better to post my ideas in this group instead of making a issue. Thanks for reading ^^ -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/134fd31b-9081-4d22-b098-412244338fc5n%40googlegroups.com.