Lately I was playing with google's new programming language Go
and was wondering why the assignment operator :=
has a colon in front of the equal sign =
Is there a particular reason why the authors of the language wanted to use name := "John"
instead of name = "John"
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand. C += A is equivalent to C = C + A. -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand.
"=" is assignment,just like other language. <- is a operator only work with channel,it means put or get a message from a channel. channel is an important concept in go,especially in concurrent programming.
Since Go does not support operator overloading, ordinary functions must be used to manipulate user types.
Go is a general-purpose language designed with systems programming in mind. It is strongly typed and garbage-collected and has explicit support for concurrent programming.
The :=
notation serves both as a declaration and as initialization.
foo := "bar"
is equivalent to
var foo = "bar"
Why not using only foo = "bar"
like in any scripting language, you may ask ? Well, that's to avoid typos.
foo = "bar" fooo = "baz" + foo + "baz" // Oops, is fooo a new variable or did I mean 'foo' ?
name := "John"
is just syntactic sugar for
var name string name = "John"
Go is statically typed, so you have to declare variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With