by suchabag · 9y ago · 0 comments
Except that you can't. "You "cannot define new methods on non-local type[s],". You have to compose them. That makes the struct function definition syntax a bit moot in my opinion.
func *Receiver.method(arg int)
instead of func (r *Receiver) method(arg int)
The advantage is that you get to name the receiver instead of having to use a keyword name like `this` or `self`. I've come to like this design decision.self, at least if you're talking about Python, is not a keyword, it's just a convention. You can use whatever your want.
You can't have:
func (r *otherPackage.Receiver) method(arg int)
Do you know why Go authors decided to put method definitions outside types definitions? Technically I don't see anything to stop the syntax from supporting the otherwise.