3 ms·
You can obviously abuse C++ templates, because they are more (or less, depending on how you look at it) than simple generics. However, in what way can parametri
by wtetzner 7y ago
You can obviously abuse C++ templates, because they are more (or less, depending on how you look at it) than simple generics. However, in what way can parametric polymorphism be misused or be a crutch for bad designs? I can't think of an example that wouldn't be horribly contrived.
- bsaul 7y agoWell, parametric polymorphism in the case of go would probably just be a performance optimisation over function taking interface as parameter, right ? i usually see monsters when you combine generics with objects and inheritence, but you're right that since go also doesn't provide those... i think when talking about generics in go we also mean struct accepting generic components. Not just functions
- wtetzner 7y agoSure, and I still don't really see a problem with it. Yes, it makes the compiler more complex, but I can't think of any ways it could be abused more than the existing language features. And it would make a lot of programs written in Go simpler.
- bsaul 7y agoBecause go is very used in data plumbing code, i found that many functions can actually work fine at the byte array level, and that it leads to a better design. It would be very tempting with proper generic support to try to have every function work with the topmost types, just because we assume it provides more type safety. I could imagine a struct representing a "User" byte array, or other atrocities.
- hderms 7y agoit's a mystery, especially to anyone who has ever seen JSON handling code in Go, that they would think generics are a crutch for bad design.