Re:Decorators in Go using embedded structs
by whateveracct on Wednesday October 23, 2019 @02:17PM
(#21337290)
Sometimes you need this though. For instance, if you do a type alias on a UUID, it will fail to marshal to SQL. But if you do a singleton embedded struct, it will work fine. I'm not gonna waste my time writing Scan and Value every time I newtype
Re:Decorators in Go using embedded structs
by weberc2 on Wednesday October 23, 2019 @01:54PM
(#21337079)
> Inheritance with embedding is a false friend in Go. Stick to composition.
Note that this applies to every language with inheritance. Composition is _always_ better.
Re:Decorators in Go using embedded structs
by AYBABTME on Wednesday October 23, 2019 @02:04PM
(#21337177)
I don't disagree. I just think it's particularly bad in Go.
Re:Decorators in Go using embedded structs
by pm90 on Wednesday October 23, 2019 @03:49PM
(#21338183)
Do you say this specifically because of struct embedding?
Re:Decorators in Go using embedded structs
by edem on Wednesday October 23, 2019 @03:35PM
(#21338035)
Using Go will lead to pain long term, so I don't think any of this matters. :)
Re:Decorators in Go using embedded structs
by thinkingkong on Wednesday October 23, 2019 @02:17PM
(#21337292)
Are there any cases where you would make use of this?
If you want to delegate a call to a "subtype", simply invoke the method on the subtype by writing it out in long form. It doesn't make you feel as intelligent but it's way more robust and won't come back to bite you down the line.