News for hackers. Stuff that matters.
Re:Decorators in Go using embedded structs by fabianlindfors on Wednesday October 23, 2019 @12:10PM (#21336035)
If we have an io.Reader which implements io.ReaderTo then it has a certain set of exported functions. If this is embedded in ioutil.NopCloser then all those exported functions will be available on ioutil.NopCloser. Wouldn't structural typing then ensure that ioutil.NopCloser implements io.ReaderTo as well as io.Reader?

Sorry if I'm misunderstanding!

Re:Decorators in Go using embedded structs by omegabravo on Wednesday October 23, 2019 @01:27PM (#21336814)
https://play.golang.org/p/V3eWfbDGhXF

In this example, by wrapping an interface in another interface, you lose the ability to cast back down to an interface that the original type fulfilled.

Re:Decorators in Go using embedded structs by fabianlindfors on Wednesday October 23, 2019 @01:48PM (#21337019)
Thanks for putting that together, I see your point know. Thought you were talking about embedding when you said "wrap" before.

Considering that this is not related to embedding specifically, would you say that decorators in general are bad practice in Go?

Re:Decorators in Go using embedded structs by weberc2 on Wednesday October 23, 2019 @02:26PM (#21337377)
This is often a reasonable thing to do (encapsulation). Callers don't have a right to private details, and I would go further and say that an interface value's concrete type is itself an implementation detail that callers shouldn't depend on unless the interface's documentation declares it stable.
Re:Decorators in Go using embedded structs by tedunangst on Wednesday October 23, 2019 @01:04PM (#21336607)
NopCloser returns an io.ReadCloser. Where are the extra functions?