Reputation: 22478
I was learning about Go and was wondering if there is a name for the :=
operator. As in x := 4
.
The best I can come up with is the "spider face".
(source: buzzfed.com)
The reason I ask is because I'm wondering how you would read the code out loud as in during a pair programming session. It's been brought up that the official name of the operator is the "short variable declaration operator" but this is ironically too long of a name to be used frequently.
How would you read this x := 4
? So far I have "ex colon equals four" or "ex spider-face four"? Are there any better ideas?
Upvotes: 7
Views: 1098
Reputation:
According to the specification at https://golang.org/ref/spec#Operators, Operators combine operands into expressions.
, this is definitely not an operator
. (if you are unsure what exactly is an operand or an expression, figure out it can not combine. Otherwise, always check the spec https://golang.org/ref/spec#Expressions).
The paragraph about this aspect of the language available in the specification https://golang.org/ref/spec#Short_variable_declarations does not name it.
The same paragraph available in the Effective Go does not name it either, https://golang.org/doc/effective_go#redeclaration
Searching the source, i was available to find how it is defined.
https://cs.opensource.google/go/go/+/master:src/go/token/token.go;drc=master;l=80
I came to the conclusion that it is the define token.
Upvotes: 1
Reputation: 199215
What about "declare as"
x := 4
You would say either: "declare ex as four" or "ex declared as four"
If that's written as
var x = 4
It's also correct
Upvotes: 3
Reputation: 9099
This is just off the top of my head, but I'd call it "instantiate". IMHO, assign is not a good choice as it confuses it with the Pascal assignment operator. Assign is also the verb used for the "=" in go and most other computer languages.
"decinit" might work as a short-hand and that has no other meaning that I know of.
Upvotes: 1
Reputation: 79983
Assign? Or 'is assigned'. Actually, I'd use 'assign' but I have to type at least 30 characters...
Upvotes: 4
Reputation:
The Go Programming Language Specification calls the declarations involving :=
“short variable declarations.” Hence the operator would be called the “short variable declaration operator.”
Upvotes: 7