You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are never allowed to make a copy of a value that a pointer points to. No integrity in that.
By not including pointer semantic methods the compiler is restricting the ability of this shared piece of data to be copied. We don't want that.
If you are in value semantic mode, we want copies of data to be stored inside of the interface. We want to maintain our value semantic consistency.
If you choose pointer semantics you are restricted to just share. If you choose value semantics let's copy, however there are times where you are in value semantic mode you might need to switch to pointer semantics (e.g., decoding, unmarshalling) and once you switch into pointer semantic mode you are locked in until you come back out of that call chain.
Scratch notes
Rules in the Go spec that define what methods, for a particular type, get bound to the value of that type:
value types, require value semantics (value receivers)
pointer types, allow pointer or value semantics (value or pointer receivers)
Relevant to method sets for implementing interfaces.
Values of type user do not implement the interface because pointer receivers don't belong to the method set of a value.
References
https://www.youtube.com/watch?v=Z5cvLOrWlLM
https://github.com/ardanlabs/gotraining/blob/master/topics/go/language/interfaces/example3/example3.go
https://play.golang.org/p/w981JSUcVZ2
The text was updated successfully, but these errors were encountered: