开发者

Simultaneous assignment in Go

开发者 https://www.devze.com 2023-02-01 08:38 出处:网络
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,

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

精彩评论

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