Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: permit iota, omission of init expressions in var declarations #21473
This was discussed very early in the language design, at the same time when we also introduced iota for constant declarations: Permit iota and the omission of initialization expressions not only in constant but also variable declarations. For instance, this would permit code like:
If my memory serves me right, we didn't pursue it at the time because there was no compelling or urgent argument in favor of it.
Such a mechanism could simplify the construction of related named objects and open the door to "enum" values that are not restricted to constant values and their respective types.
As such it may be a more elementary building block towards more complex "enums" in Go (see also the discussion in #19814).
I know it's the same as with constant, it's just now double the surface. So questions also like "Why do my var-enums not work?" will be coming. I don't think adding the feature is worth complicating the language.
@cznic It's arguably less complexity in the language because now the same syntax and mechanism can be used for constants and variables. The question you're afraid might be coming up would have surfaced already now as it's quite common to have sequences of grouped constant declarations.
Unrelated: The reason I brought this issue up in the first place is that it might be another stepping stone towards addressing the desire for "enums" by some. Making it easier to declare groups of variables, perhaps together with a mechanism to enumerate over them might be a more Go-like approach than the the more heavy-weight enum support that is found in other languages.