News for hackers. Stuff that matters.
Re:Introduction to Go 1.1 by Jabbles on Tuesday March 26, 2013 @10:08AM (#5443344)
You can't add methods to a type in a different package as you might break that package. By locking the method set of types when a package is compiled you provide some guarantee of what it does, and it doesn't need to get recompiled again! This is central to Go's ideals of compiling fast.

Besides, embedding a type is very easy http://golang.org/ref/spec#Struct_types

Re:Introduction to Go 1.1 by GhotiFish on Tuesday March 26, 2013 @10:23AM (#5443454)
Hmmm. I can see how adding methods to a type in a different package would require that package to be recompiled, but I don't see how I could break that package. Unless there's some reflection magic I'm not considering.

I'm reading through the embedded types now. I am new to golang so this one is lost on me. I thought if you wanted your own methods on a type from another package, you just aliased it with your own type def.

though it looks like there's some kinda prototyping behavior being described here?

    If S contains an anonymous field T, the method sets of S and *S both include
    promoted methods with receiver T. The method set of *S also includes promoted 
    methods with receiver *T.
    
    If S contains an anonymous field *T, the method sets of S and *S both include 
    promoted methods with receiver T or *T.
Re:Introduction to Go 1.1 by Jabbles on Tuesday March 26, 2013 @10:46AM (#5443612)
For example, if you do a runtime type assertion to see if a variable satisfies an interface:

    v, ok := x.(T)
http://golang.org/ref/spec#Type_assertions

If you "monkey-patch" x to satisfy T in another package, the value of ok may change.

Re:Introduction to Go 1.1 by GhotiFish on Tuesday March 26, 2013 @11:11AM (#5443798)
Hmm I can kind of see what you mean, but I don't see it as a big of a problem.

If you make package A depend on package B, package B monkey-patches x with method Foo so now x is a Fooer

x now satisfies the Fooer interface in package A, well that seems ok. You imported B after all. In things that don't import B, x doesn't satisfy Fooer. Is this unexpected behavior? If B depends on C, C's x won't satisfy Fooer right?