2 ms·
Not quite sure why this isn't just type foo int: func MethodA(): pass Analagous to this: type foo int func (foo) MethodA(){} Why openi
by NateDad 10y ago
Not quite sure why this isn't just
type foo int:
func MethodA():
pass
Analagous to this:
type foo int
func (foo) MethodA(){}
Why opening and all that? Or is that a way to add methods to types outside the current package? If so, you're opening up a whole new can of worms.
- wowoc 10y agoYour example looks good as well. Opening gives more flexibility with how the code can be structured, say that you have two interfaces: type I interface { A() } type J interface { B() } And you have two structs that implement them, you can then group methods from the same interface together: type X struct{} type Y struct{} func (x X) A() {} func (y Y) A() {} func (x X) B() {} func (y Y) B() {} I've seen that used in the Golang codebase, and sometimes it does seem useful.