开发者

Simultaneous assignment in Go

I'm learning Go and can't understand one thing, why creators of this language do support simultaneous assignment? It is very easy to make mistakes lik开发者_如何学JAVAe a, b = a, b and not a, b = b, a, as I would want, thanks in advance for any good explanations.


It is very easy to make mistakes like a, b = a, b and not a, b = b, a,

If simultaneous assignment were not available then you would have to do something else instead. An alternative approach might look something like this:

tmp = a
a = b
b = tmp

That's much easier to get wrong.


How else would you get access to the second, third, fourth, … return value of a function?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜