3 ms·
>About generic, when I thought need it, I always able to find simpler design using composition. How exactly would composition help you e.g. make a general purp
by coldtea 9y ago
>About generic, when I thought need it, I always able to find simpler design using composition.
How exactly would composition help you e.g. make a general purpose reusable math library for different kinds of numeric types?
- jitl 9y agoI think the implicit argument is that “a general purpose reusable math library for different kinds of numeric types” is not a real problem. A real problem is, “I need to draw this triangle”, and using math.Cos w/ float64s works just fine.
- coldtea 9y agoAnd yet it's a problem anybody who makes any kind of library that should work with > 1 types, faces... Not just math and scientific libraries. Even a simple reusable data structure. And fact it's so commonly needed for this, that Go's slices and maps would have been useless unless Go's designers have not cheated and used genericity for themselves... And let's not get into reusable abstractions for behavior -- like a library that encapsulates the 5-10 more common uses for channels and goroutines (span N goroutines and wait for all to collect the results, span N and use first result, and so on).
- wejick 9y agoYou could say my usecase is on different scope than that. But I still on the against side of the generic. It will add (for me unnecessary) complexity to the language. Cmiiw even when have generic in place, we still need to write the code for each type right? Just the interface is the same. (this argument sounds silly actually, just want to say that)