design - Why does assigning to a variable in Go have an equal sign -


i upfront i'm starting learn , use go language , isn't syntax question more of language design question.

in go, assuming have channel c of int, can send on channel using:

c <- 1 

and receive channel variable v with:

v = <- c 

i've read simple way remember syntax "arrow" points in direction in information flowing, think poetic, being quite python fan. question why not taken way have symmetric syntax:

v <- c 

in order receive channel? why have equals sign there?

i suppose interpreter end adjacent syntax tokens like:

[variable][value] 

which conceivably come statement like:

v 1  

so equals sign there allows reuse usual variable assignment machinery making channel receipt evaluate value. difficult make interpreter accept version without equals sign though? have treat binary operator case.

it seems lead other cases if there 2 channels c1 , c2 have syntax:

c2 <- <- c1 

in order read 1 , transmit other.


i'd i'm not trying elicit opinions on style rather trying understand decisions drove go way is.

combining 2 orthogonal operators each doing 1 thing more expressive.

in addition examples provided @sedat-kapanoglu, think how express following:

x := <-ch x += <-ch x, y = <-ch1, <-ch2 

also proposal following expression:

y <- x 

could read channel x or write channel y depending on types x , y. compare code uses existing syntax:

y = <-x y <- x 

Comments