I would like to say upfront that I'm only starting to learn about and use the Go language and also that this isn't a syntax question but more of a language design question.
In Go, assuming that you have a channel c
of int
, you can send on the channel using:
c <- 1
And receive from the channel into a variable v
with:
v = <- c
I've read that a simple way to remember the syntax is that the "arrow" points in the direction in which information is flowing, which I think is poetic, especially being quite the Python fan. My question is why is this not taken all the way so you have the symmetric syntax:
v <- c
in order to receive from a channel? Why have the equals sign there?
I suppose the interpreter would end up with adjacent syntax tokens like:
[variable][value]
which could conceivably come from a statement like:
v 1
So that the equals sign there allows you to reuse the usual variable assignment machinery by making that channel receipt evaluate to a value. Would it be that difficult to make the interpreter accept the version without the equals sign though? It would basically just have to treat it as a binary operator for that case.
It also seems to lead to other cases where if there are two channels c1
and c2
you have the syntax:
c2 <- <- c1
In order to read from one and transmit it into the other.
I'd like to also say that I'm not trying to elicit opinions on style but rather trying to understand the decisions drove Go to be the way it is.