In-reply-to » My take on the discussion to introduce an ? operator in Go 👈 No. For so many reasons.

@prologic@twtxt.net Which one? I don’t mind the ternary operator at all. In fact, I often find myself missing it in Go. I don’t find the two alternatives particularly elegant:

foo := "eggs"
if bar {
    foo = "spam"
}

Or:

var foo string
if bar {
    foo = "spam"
} else {
    foo = "eggs"
}

To my eye, this just would look a lot nicer:

foo := bar ? "spam" : "eggs"

Or at least as the Pythons do it:

foo = "spam" if bar else "eggs"

The ternary operator especially shines with relatively short expressions.

⤋ Read More