英文:
What do you call the := operator?
问题
我正在学习Go语言,想知道:=
运算符有没有一个名称。比如x := 4
。
我能想到的最好的名称是**"蜘蛛脸"**。
示例
<sub>(图片来源: buzzfed.com)</sub>
更新
我之所以问这个问题,是因为我想知道在进行配对编程时,你会如何大声读出这段代码。有人提到这个运算符的官方名称是"短变量声明运算符",但这个名称太长了,不太适合频繁使用。
你会如何读出x := 4
?到目前为止,我想到的是"ex冒号等于四"或者"ex蜘蛛脸四"?有更好的建议吗?
英文:
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
<sub>(source: buzzfed.com)</sub>
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?
答案1
得分: 6
Go编程语言规范将涉及:=
的声明称为“短变量声明”。因此,该运算符将被称为“短变量声明运算符”。
英文:
The Go Programming Language Specification calls the declarations involving :=
“short variable declarations.” Hence the operator would be called the “short variable declaration operator.”
答案2
得分: 4
分配?还是“被分配”。实际上,我会使用“分配”,但是我必须输入至少30个字符...
英文:
Assign? Or 'is assigned'. Actually, I'd use 'assign' but I have to type at least 30 characters...
答案3
得分: 3
“declare as”可以翻译为“声明为”。
x := 4
你可以说:“将ex声明为四”或者“ex声明为四”。
如果写成
var x = 4
也是正确的。
英文:
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
答案4
得分: 1
这只是我脑海中的一个想法,但我会称之为“实例化”。在我看来,assign不是一个好的选择,因为它会与Pascal的赋值运算符混淆。Assign也是go和大多数其他计算机语言中用于“=”的动词。
"decinit"可能作为一个简写也可以,我不知道它有其他的意思。
英文:
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.
答案5
得分: 0
根据 https://golang.org/ref/spec#Operators 上的规范,"运算符将操作数组合成表达式",这绝对不是一个"运算符"。(如果你不确定什么是操作数或表达式,请确定它们不能组合。否则,始终检查规范 https://golang.org/ref/spec#Expressions)。
关于语言的这个方面,在规范 https://golang.org/ref/spec#Short_variable_declarations 中没有给出名称。
在《Effective Go》中提到的同一段落也没有给出名称,https://golang.org/doc/effective_go#redeclaration。
在搜索源代码时,我找到了它的定义。
https://cs.opensource.google/go/go/+/master:src/go/token/token.go;drc=master;l=80
我得出的结论是它是"define"标记。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论