Comparing values will be a lot cheaper with ints than strings. So if your enum type is possibly used in hot loops, ints will be your friend. Also, with ints, you can provide an ordering that differs from the lexical order of the string values. For example, with an int, you can easily sort by day-of-week by defining the constants in order. With strings, you have to use a custom compare function that acts on string names (ick).
---- *Josh Humphries* jh...@bluegosling.com On Sun, Oct 15, 2017 at 4:13 PM, <m...@inanc.io> wrote: > Is it anything wrong just assigning string values to get rid of String() > method attaching? > > *Like this:* > > type Weekday string > > const ( > Sunday Weekday = "Sunday" > Monday Weekday = "Monday" > ) > > func main() { > fmt.Println(Sunday) > } > > > > *Instead of this:* > > type weekday uint > > const ( > Sunday weekday = iota > Monday > ) > > var weekdayNames = [...]string{"Sunday", "Monday"} > > func (day weekday) String() string { > return weekdayNames[day] > } > > > func main() { > fmt.Println(Sunday) > } > > > > Thanks. > > -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.