Atmocreations
Atmocreations

Reputation: 10071

Go "this"-keyword

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
}

Upvotes: 24

Views: 16587

Answers (1)

publysher
publysher

Reputation: 11372

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.

Upvotes: 24

Related Questions