Start Enums at One
The standard way of introducing enumerations in Go is to declare a custom typeand a const
group with iota
. Since variables have a 0 default value, youshould usually start your enums on a non-zero value.
Bad | Good |
---|---|
|
|
There are cases where using the zero value makes sense, for example when thezero value case is the desirable default behavior.
- type LogOutput int
- const (
- LogToStdout LogOutput = iota
- LogToFile
- LogToRemote
- )
- // LogToStdout=0, LogToFile=1, LogToRemote=2