4 ms·
iota is much more general than just enumerations. http://golang.org/ref/spec#Iota http://golang.org/ref/spec#Iota A neat example is using it to define constant
by dsymonds 15y ago
iota is much more general than just enumerations. http://golang.org/ref/spec#Iota http://golang.org/ref/spec#Iota
A neat example is using it to define constants for a bit field:
const (
A = 1 << iota
B
C
)
- pjmlp 15y agoIt pollutes the global namespace, plus it is a common enumeration feature that you can give initial values to the enumeration elements, so I fail to see iota benefit.
- 4ad 15y agoThere is no global namespace in Go. The fact that you don't know this trivial thing means you nothing about Go and only spread FUD.
- pjmlp 15y agoDon't put words in my mouth please. Each package has a global namespace, so each const has to be unique at the package level to avoid namespace collisions. With proper enumerations, only the enumeration needs to be unique, while the enumeration elements would be scoped to the enumeration level, as most (not all) languages do.
- dsymonds 15y agoYou keep using that word, "global". I do not think it means what you think it means.