DEV Community

Discussion on: Why doesn't Go have Ternary?

Collapse
 
fjones profile image
FJones

The one use-case ternaries would have in go is assigning a conditional value to a read-only variable. Given the overall ethos of Go programming, however, that very use-case would be more of a code smell than anything else. So ultimately ternaries are just syntactic sugar with more drawbacks than benefits from a language design POV.

However, Go has its fair share of syntactic sugar already (e.g. optional return, and defer), so it's questionable whether that alone should be an argument against ternaries. Though I do tend to agree that it shouldn't make it into the syntax.