What do you call the := operator?

752 views Asked by At

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".

Example

enter image description here
(source: buzzfed.com)

Update

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?

5

There are 5 answers

0
Fred the Magic Wonder Dog On

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.

2
AudioBubble On

The Go Programming Language Specification calls the declarations involving := “short variable declarations.” Hence the operator would be called the “short variable declaration operator.”

0
Magoo On

Assign? Or 'is assigned'. Actually, I'd use 'assign' but I have to type at least 30 characters...

1
OscarRyz On

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

0
AudioBubble On

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.