5 ms·
I've often wondered about this. Does this technique (a type safe wrapper around an interface{}ing class) kind of accomplish the same thing that generics do for
by moldavi 5y ago
I've often wondered about this. Does this technique (a type safe wrapper around an interface{}ing class) kind of accomplish the same thing that generics do for Java? It would result in the same kind of type-erasure in the end, I'd assume.
In a weird way, with this technique, did Go have "manual generics" all along?
- pharmakom 5y agoExcept you still have to write out the typed implementation - even if it is small. In Java this is not necessary.
- masklinn 5y ago> In a weird way, with this technique, did Go have "manual generics" all along? In the exact same way every langage without generics had generics all along: not in any meaningful way. You could also use codegen hook to instantiate your pseudo-generics after all: https://www.reddit.com/r/rust/comments/5penft/comment/dcsgk7n https://www.reddit.com/r/rust/comments/5penft/comment/dcsgk7...
- cratermoon 5y agoNot really, but aside from the functional aspect that tends to come with them, all generics are really saying is "this operation will performed on a type to be named at runtime", optionally with a constraint that says the type-to-be-named-later will adhere to a certain interface (contract).
- cben 5y agoOn a type to be named _separately_. To-be-named-at-runtime is simply dynamic typing. It's polymorphism without static typing. Generics based on type erasure, e.g. Java, wrap that with a type system hoping* to prove safety at compile time, yet compile to a single dynamicly typed implementation, that does not use this type info at runtime. Generics based on code generation / specialization, e.g. C++, generate distinct run-time implementations with the type hard-coded. (Though you can plug in dynamic typing by making the hard-coded type a pointer.) In C++ this is more than optimization, it's semantics — you can specify distinct behavior for specific types. JIT compilers can start from a single dynamic-dispatch implementation and generate specialized implemetations for some types, bridging the divide. But in any case, the common meaning of "generics" is not merely polymorphism, it's polymorphism plus a type system where you _name_ the type you're gonna use. * https://3fx.ch/typing-is-hard.html#java https://3fx.ch/typing-is-hard.html#java