Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 231
    So just because what the language designers have seen, they have omitted a one-liner for a whole if-else block? And who says if-else isn't abused in like manner? I'm not attacking you, I just feel that the excuse by the designers isn't valid enough Commented Jun 9, 2020 at 11:42
  • 64
    I agree. Ugly ternarys are a coding problem, not a language problem. Ternarys are common enough across languages that they are normal and not having them is a surprise, which violates POLA/PLA if you ask me. Commented Jun 24, 2020 at 17:41
  • 4
    But think of it from the language designer's perspective; they need to extend the language specification, parser, compiler, etc with extra syntax that isn't used anywhere else in the language for some syntactic sugar that is a potential readability footgun. Go is designed for reading, and while most C-developers may be familiar enough with ternaries to be able to read them quickly enough, this is not a universal truth, and things go really south when people start nesting them. "This other language has it" is NOT a valid argument to add a language feature. Commented Aug 13, 2020 at 14:47
  • 17
    The explanation from the language's designers looks weird because it contradicts another language feature: if including 2 statements separated by semicolon (see tour.golang.org/flowcontrol/6). I doubt that the second one makes the code clear. They could have implemented ternary if with limitation of just one '?' per statement. Commented Mar 11, 2021 at 19:15
  • 22
    "A language needs only one conditional control flow construct." - Sure, but why not make if an expression and allow constructs like `if cond { value1 } else { value3 } like Rust or Scala? Commented Dec 30, 2021 at 16:44