Avoiding Reflection (And Such) in Go
&gt; Because composition doesn&#x27;t intermingle objects the way inheritance does, it allows much more interesting &quot;chains&quot; of objects to be created that extend each other, without the complexity exploding.<p>Go&#x27;s (really Plan 9 C&#x27;s) composition support does &quot;intermingle&quot; methods, which has pretty much the same effect as intermingling fields. To see this, note that Go needs rules about who wins if methods for an outer object and an inner object have the same name (and they have to consider diamonds, which you can have with composition!)<p>&gt; So, &quot;Go doesn&#x27;t have generics&quot; is only half true.<p>I know this is going to be me annoying about terminology, but I really disagree. :) Go has <i>polymorphism</i>. It doesn&#x27;t have <i>generics</i>, at all. &quot;Generics&quot; has a specific meaning: the ability to take types as parameters.<p>&gt; It can be profitably argued that the primary virtue of &quot;generics&quot; is generic algorithms rather than generic types.<p>I don&#x27;t agree. Generic types are necessary, because you often can&#x27;t express generic algorithms naturally without generic types.  Just as an example of where I needed generics in my work most recently, I wrote a polygon clipper over the past couple of weeks that has special fast paths when it clips rectangles and falls back to Sutherland-Hodgman clipping for complex polygons. This was natural to express by making the clipping result generic over the type of polygon (rect or edge list). I could maybe have done it in Go by using the &quot;container-as-interface&quot; trick that the sort package uses, but that would introduce a lot of boilerplate.<p>There&#x27;s also the issue that all these interfaces make it awfully hard for the optimizer to produce as good code as it would if you actually had generics. Unless you inline everything away (in which case SROA and constant propagation can mostly get you there), you&#x27;d need a nontrivial interprocedural analysis. Performance issues around generic programming tend to have outsized effects, because functions that tend to be generic are precisely those functions that tend to be called a lot (because they&#x27;re generic!) and shoot to the top of the profile.<p>&gt; As a side note, if Go ever does grow full generics, I expect it to do so by extending the half it has, rather than adding a new concept of generics on the side. It&#x27;s easy to imagine a generic BalancedBinaryTree that requires its nodes to conform to a LessThan interface.<p>This I agree on entirely. Note that this is pretty much exactly what Swift did :)<p>&gt; If you have a constrained set of messages, for instance, you can use the type system to more carefully declare them as coming from a particular set of types, not just interface{}.<p>But you lose half of the point of sum types, in that the compiler can check exhaustiveness for you. It&#x27;s worse, because since you&#x27;re doing a Go type switch, you can match against cases that aren&#x27;t even in the sum type and the compiler won&#x27;t complain! It&#x27;s also an awful lot of boilerplate to create a half-approximation-of-a-sum-type, meaning that the ergonomics favor people not using it. interface{} is just plain easier to use compared to the sum type pattern, which is why it gets so much use.<p>&gt; Go still manages to cover so much with its meager feature set. There&#x27;s a lesson here for language nerds. I don&#x27;t fully know what it is yet, but I&#x27;m working on it.<p>I think the lesson is &quot;people will figure out design patterns to approximate things that your language doesn&#x27;t support&quot;. This is no surprise: people write OO systems in the C preprocessor. But I think it would be a mistake to conclude &quot;omit useful features from the language if there&#x27;s any way people can possibly approximate them&quot;. This was the approach that Java famously took, and people rightfully soured on the extreme emphasis on &quot;design patterns&quot;. And what you&#x27;ve described in this post is nothing more than a set of design patterns. Design patterns have their place and are very useful, but they&#x27;re also the sincerest form of feature request.