4 ms·
> Generics are nice to have, but I think people blow them wildly out of proportion. The main alternative is code generation, which is slow, brittle and hostile
by jacques_chester 6y ago
> Generics are nice to have, but I think people blow them wildly out of proportion.
The main alternative is code generation, which is slow, brittle and hostile to easy version control.
I'd rather have a code type system than a system typing out code.
- erik_seaberg 6y agoCodegen can work around weakness in a language, but the key is a build system that generates code, compiles it, and then throws it away. Checking it in is a mistake, because you have to start reviewing it if there’s any possibility of editing it.
- throwaway894345 6y agoFully agree that generic type system is nicer than code generation; however, code generation thankfully isn't the only alternative nor even the best. Rather, as previously mentioned, we can use `interface{}` which is roughly the same as using dynamic types for the relevant bit of code. If people can make blockbuster apps with dynamically typed languages (100% of code paths are dynamically typed), it's really not a big deal that Go makes you drop into dynamic typing for <5% of code paths.
- jacques_chester 6y agoI don't see interface{} as an improvement over code generation.
- throwaway894345 6y agoI think you'll find that your opinion is very fringe, but by all means, go forth and use code generation.
- jacques_chester 6y agoMy opinion is that I greatly prefer generics to either.
- loopz 6y agoHaving genetics as a good option is great. Using interface{} works too, but is a kludge if you have to do it alot. You lose performance to reflection and gain runtime errors that are hard to handle. It's not the best part of Go, far from it.