proposal: spec: exhaustive switching for enum type-safety
- **Would you consider yourself a novice, intermediate, or experienced Go programmer?** Intermediate, multiple projects, plenty of learning - **What other languages do you have experience with?** JS/TS, Swift, Python, C#, C++ - **Has this idea, or one like it, been proposed before?** Yes, the enums are a popular under proposal subject matter. - **If so, how does this proposal differ?** It doubles down on the status quo (aka historically idiomatic) solution for enums in Go. All current Go enum declarations will remain valid. Instead of introducing new keywords or interfering with existing patterns (such as the Stringer interface) it adds tools for enforcement and runtime-safety of enumeration usage. It does so by employing existing type assertion and type casting idioms, and the `const` keyword idiomatic to Go enum declarations. - **Who does this proposal help, and why?** For those adopting enums in Go, it is important to limit their use to the values known at compile time, or explicitly opt-in to the type-casting and therefore verifying the primitive values. The new syntax will not eliminate the need for authors of packages exposing an enumeration type to create checks on enum usage. Rather, this proposal will clarify the party **responsible** for enum value validation and provide tools that will make that validation idiomatic, clearly identifiable and easy to implement. - **Is this change backward compatible?** Yes. - **Show example code before
Posted by ermik on Jan 4, 2020, 10:56 PM
Tags
Related issues
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
reliability (EdTech)
I frankly find the situation around UB puzzling.
I think it depends a little on how and where you work.
Self modifying has some sneaky failure modes with modern CPUs.
> Ban phones from class.
Coolify v5.x
Are you talking about a technical problem, or a conceptual problem?
This is not uncommon in the more blue-collar businesses.
> I wonder though, do people not strace programs any more?
proposal: spec: exhaustive switching for enum type-safety
- **Would you consider yourself a novice, intermediate, or experienced Go programmer?** Intermediate, multiple projects, plenty of learning - **What other languages do you have experience with?** JS/TS, Swift, Python, C#, C++ - **Has this idea, or one like it, been proposed before?** Yes, the enums are a popular under proposal subject matter. - **If so, how does this proposal differ?** It doubles down on the status quo (aka historically idiomatic) solution for enums in Go. All current Go enum declarations will remain valid. Instead of introducing new keywords or interfering with existing patterns (such as the Stringer interface) it adds tools for enforcement and runtime-safety of enumeration usage. It does so by employing existing type assertion and type casting idioms, and the `const` keyword idiomatic to Go enum declarations. - **Who does this proposal help, and why?** For those adopting enums in Go, it is important to limit their use to the values known at compile time, or explicitly opt-in to the type-casting and therefore verifying the primitive values. The new syntax will not eliminate the need for authors of packages exposing an enumeration type to create checks on enum usage. Rather, this proposal will clarify the party **responsible** for enum value validation and provide tools that will make that validation idiomatic, clearly identifiable and easy to implement. - **Is this change backward compatible?** Yes. - **Show example code before
Comments (0)
No comments yet. Start the discussion.