Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 like a, b = a, b and not a, b = b, a, as I would want, thanks in advance for any good explanations.

like image 804
rookie Avatar asked Dec 25 '10 23:12

rookie


2 Answers

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.

like image 169
Mark Byers Avatar answered Nov 09 '22 23:11

Mark Byers


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

like image 24
Jörg W Mittag Avatar answered Nov 10 '22 00:11

Jörg W Mittag