Hacker News new | ask | show | jobs
by 1_player 4063 days ago
No, please don't. Go structs are not C unions. Please see my other comment in this thread about using Go interfaces.
1 comments

I disagree. Sometimes an interface is not appropriate; just because you have two things that are alike doesn't mean that they implement an interface.

"A circle, triangle, or rectangle" is not the same data structure as "Something that can be drawn". Certainly if you have a function that draws something given a Draw() method, having the function take a "Drawable" is appropriate. But it's not the only use case; sometimes you really mean "A circle, triangle, or rectangle" and in that case, a struct is absolutely what you want.