TLDR Tech / Practical
Go enums using iota can accept any integer, including 42
The article examines various Go enum implementation strategies, contrasting iota-based named integer types with struct wrappers and sealed interfaces. It points out that while named integer types can accept any integer, including out-of-range values, using them with iota + 1, validation logic, and the exhaustive linter provides robust compile-time and runtime security. The author advocates for integer types paired with validation and linters for most scenarios, reserving sealed interfaces for cases involving distinct data.
Read the full story