4 ms·
Go has some selected generic data types: array, slice (think of ArrayList<T>), map, channel, func. I found these to be sufficient for 90% of my problems. In 9%
by mseepgood 14y ago
Go has some selected generic data types: array, slice (think of ArrayList<T>), map, channel, func. I found these to be sufficient for 90% of my problems. In 9% of the cases I craft non-generic data structures based on interfaces, which are specific to my problem domain. For the rest I can live with interface{}.
- CJefferson 14y agoI really dislike languages which decide to bless some special data-structures, but then won't let me add my own generic data structures. Of course, I really love data structures, so I can understand other people who just want to get on with things, and are happy to slightly abuse some built-in data structures to get most of the way there.
- luriel 14y agoGo doesn't stop you from building datastructures, actually is really nice for building datastructures. It simply doesn't provide a simple way to build some kinds of generic datastructures, but when the ones provided by the language are not enough it usually means your problem is specialized enough that a custom datastructure is best anyway, and Go makes that pleasant and easy. And then there are interfaces, which are a kind of "generics" of their own.
- fauigerzigerk 14y agoI don't like the special treatment for builtin data structures either. But if the alternatives are ending up in a mental institution (C++ templates) or in a Potemkin village (Java), I'd rather live with this inconsistency for a while. Maybe (hopefully!) these are not the only alternatives.
- djhworld 14y agoI'm currently going through an algorithms textbook and find that algorithms and generics go hand in hand in writing generic, type safe reusable algorithms in your code. Having to rewrite the same code over and over again to support one algorithm is a real pain in the butt. ...and the interface{} thing is just a workaround that defers type errors until runtime. Which in turn defeats the point of enjoying a type safe language
- deleted 14y ago[deleted]