I use VS Code Go extension.
Here's my code
func (this *MyClass) Xxx() error {}
And It's mention me this
exported method
MyClass.Xxx
should have comment or be unexportedreceiver name should be a reflection of its identity; don't use generic names such as "
me
", "this
", or "self
";
As mentioned here
v.Method()
is actually syntactic sugar and Go also understands the de-sugared version of it:(T).Method(v)
. You can see an example here.
package main
type T struct{}
func (t T) Method() {}
func main() {
t := T{}
t.Method() // this is valid
(T).Method(t) // this too
}
Naming the receiver like any other parameter reflects that it is, in fact, just another parameter quite well.
As Ixrec puts it in this answer:
In other languages the
this
/self
/whatever
variable typically has some special properties such as being magically provided by the language, or having special access to private methods (remember Go doesn't have private fields/methods).
Though the "receiver" is still being "magically provided" to some extent, it's so similar to a regular function argument it arguably doesn't count.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With