News for hackers. Stuff that matters.
Re:Functional Programming in Go with Generics by moldavi on Thursday May 27, 2021 @02:03AM (#27299878)
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?

Re:Functional Programming in Go with Generics by masklinn on Thursday May 27, 2021 @03:28AM (#27300350)
> 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/dcsgk7...

Re:Functional Programming in Go with Generics by pharmakom on Thursday May 27, 2021 @02:43AM (#27300119)
Except you still have to write out the typed implementation - even if it is small. In Java this is not necessary.
Re:Functional Programming in Go with Generics by cratermoon on Thursday May 27, 2021 @12:22PM (#27304842)
Not 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).
Re:Functional Programming in Go with Generics by cben on Friday May 28, 2021 @10:30AM (#27315742)
On 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