Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go "this"-keyword

Tags:

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
}
like image 918
Atmocreations Avatar asked Mar 13 '15 09:03

Atmocreations


People also ask

What are the 6 Rube Goldberg machines?

The 6 Simple Machines are: wedge, screw, lever, wheel and axel, inclined plane and pulley.

Why is it called a Rube Goldberg machine?

A Rube Goldberg machine, named after American cartoonist Rube Goldberg, is a chain reaction-type machine or contraption intentionally designed to perform a simple task in an indirect and (impractically) overly complicated way.

How many takes this too shall pass?

The first day of filming included 47 takes, none of which successfully completed the entire machine and necessitated a second day of filming. Many of the takes ended only 30 seconds into the process, at the start of the song's chorus, where a tire would fail to roll properly into the next section of the machine.

What was Rube Goldberg most famous machine?

Honda's "The Cog" is probably the best known Rube Goldberg machine.


1 Answers

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.

like image 77
publysher Avatar answered Oct 18 '22 18:10

publysher