Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Various core Go team members seem to have a different philosophy regarding generics. They actually don't have a united front on this.

It seems Russ Cox and Rob Pike are either anti-generics or in the you-dont-really-need-them camp, but Ian Thompson and Brad Fitzpatrick have seemed very open to the idea - what they can't, however, agree on, is exactly how to implement them so that they make sense in Go. That's it.

If you or anyone out there manages to produce a proposal of how they should work/look like and even a fork of Go implementing the idea, it will be taken seriously, at least by some core Go members.

I have a feeling that generics are coming. And I have a feeling they'll be very Go-like - an external tool with code generation, not special syntax. Just my 2 cents.



I think adding generics to a stable language is actually a hard thing to do. There's more than "that's it". Rust has had many major and minor changes regarding generics solely, which has broken backward compatibility each time.

The Go team may find a brilliant way to accomplish this, but I think the only viable way left is, as you said, using code generation. Either C++-way, which is a special syntax but still a form of code generation, or an external tool. But neither of them is elegant, because you cannot fully utilize the convenience that the type system give. These might be the concerns that the Go team has.


Maybe the "elegance" is a factor as well, but I haven't seen it mentioned. All I've seen mentioned is: a) can't change syntax b) can't take huge performance hits at run time or at compile time c) can't break backwards compatibility d) talk is cheap - provide a working implementation

So far, nobody has been able to show all 4 of these requirements, so nothing has been done.

But when/if someone does, I expect it to be taken very seriously.


This is already a thing, no? https://blog.golang.org/generate


Almost. So close. But no cigar. Go generate is for the package creator, not the package consumer. So you, as a package creator, may create a "generic" red-black tree, but unless you pre-generate all my use cases for all my data types, I can't pull your package and then use go generate to create Tree<int> and Tree<string> if that makes sense.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: