Why does Go not have the ?: operator?
为什么Go没有?:运算符?
There is no ternary testing operation in Go.
Go中没有三元测试操作。
You may use the following to achieve the same result:
您可以使用以下方法获得相同的结果:
if expr {
n = trueVal
} else {
n = falseVal
}
The reason ?: is absent from Go is that the language’s designers had seen the operation used too often to create impenetrably complex expressions.
Go缺少?:的原因是该语言的设计师发现该操作过于频繁地用于创建难以理解的复杂表达式。
The if-else form, although longer, is unquestionably clearer.
if-else形式虽然更长,但无疑更清晰。
A language needs only one conditional control flow construct.
一种语言仅需要一个条件控制流构造。