What do you call the := operator?
Asked Answered
B

5

7

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?

Bisulfate answered 30/12, 2013 at 0:5 Comment(3)
Declare & Assign the variable x the constant value 4.Tsarina
I say "colon equals".Sello
Implicit/losely assignment operator seems like a good name for me.Glossotomy
V
7

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

Vosges answered 30/12, 2013 at 0:7 Comment(2)
Is it really an "operator"?Rhizo
It's not an operator, these are operators. Many go talks also call it "declare and initialize" (e.g. this )Explicate
M
4

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

Monjan answered 30/12, 2013 at 0:35 Comment(0)
B
3

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

Berryberryhill answered 30/12, 2013 at 18:36 Comment(1)
I like this much better than my suggestions.United
U
1

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.

United answered 30/12, 2013 at 17:49 Comment(0)
H
1

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.

Hagiolatry answered 15/9, 2021 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.