去“这个” - 关键字 [英] Go "this"-keyword
问题描述
是否有任何理由反对使用这个
type MyStruct struct {
someField字符串
}
func(this MyStruct)getSomeField()string {
return this.someField
}
没有技术性的理由不这样做。 b
它与此处所述的一般准则不符:
不要使用通用名称,例如me,this或self而不是功能。
我还想在使用这个
(或 self
),这个
总是一个指针。对于Go中的方法接收器,情况并非一定如此。
After diving into the docs I couldn't find the answer to my following question:
Is there any reason against using this
for referring to the current object as in the following example?
type MyStruct struct {
someField string
}
func (this MyStruct) getSomeField() string {
return this.someField
}
There is no technical reason not to do this.
It does go against the general guidelines as explained here:
Don't use generic names such as "me", "this" or "self", identifiers typical of object-oriented languages that place more emphasis on methods as opposed to functions.
I would also like to add that in languages that use this
(or self
), this
is always a pointer. For method receivers in Go, this is not necessarily the case.
这篇关于去“这个” - 关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!