12 ms·
I'd say generics aren't just about avoiding copy-pasting. It's also added type safety. At this point the closest thing is using an interface as a function param
by orblivion 8y ago
I'd say generics aren't just about avoiding copy-pasting. It's also added type safety. At this point the closest thing is using an interface as a function parameter. You get a dynamically typed value (albeit limited to types that implement the interface).
- lima 8y agoThe closest thing is auto-generating code, not using interface{}.
- platinumrad 8y agoYes, but there's still a depressingly large amount of code in the wild that just casts interface{} back and forth.
- lima 8y agoCommon with ORMs. The gorm API is horrible - it's all interfaces. The only reasonable ORM library I've seen is sqlboiler, which uses code generation. https://github.com/volatiletech/sqlboiler https://github.com/volatiletech/sqlboiler
- orblivion 8y agoI don't necessarily mean interface{}. This: type Thing interface { ... } is better, but Thing is still a dynamic type.
- sacado2 8y agoThat, and efficiency, as the generated code can be inlined in many cases.