Live data from Hacker News

A Proposal for Adding Generics to Go

blog.golang.org

31–40 of 273 posts

Re: A Proposal for Adding Generics to Go

#32
post #2

How many different proposals for generics have there been?

Actually not that much, I remember 2 very different proposals, including this one.

The previous one was confusing as F and the antithesis of the simplicity Go claims it abides by. It felt very much like a plot to add generics without ever using the word generics anywhere and looking too much like Java/C#/...

The current proposal is basically what you'd expect from generics in a programming language, but a bit more limited.

It took basically 10 years, a generation of developers, to quell the opposition against generics in Go, to end up with generics...

They might even have unknowingly followed the ADA implementation except that Go's type inference makes them even easier to use.

> To use a generic type, you must supply type arguments. This is called instantiation.

https://go.googlesource.com/proposal/+/refs/heads/master/des...

This is basically how generics as packages in ADA works. I would add that ADA solved many existing problems in Go decades ago...

https://en.wikibooks.org/wiki/Ada_Programming/Generics

> The generic procedure can be instantiated for all the needed types.

Now all Go needs to do is to look at how Ada tasks work in order to fix every single issue with Go routines...

Re: A Proposal for Adding Generics to Go

#33

Earlier quoted context omitted.

Why? C isn't type-safe.

C doesn’t lack safety by-design - it’s hobbled by its history and constraints imposed by its userbase - otherwise C would have major breaking changes more often.

C absolutely lacks type-safety by design. Otherwise what would malloc return, besides void*? How would you implement generic containers in C, without using macros or void*?

Edit: formatting

Re: A Proposal for Adding Generics to Go

#35

We have a very large Go codebase here at Stream and not having generics is just not really as big of an issue as you think it is. There are plenty of work arounds if you get used to not having generics in the language. The fast compile times of Go are amazing. I was doing some Kotlin a few weeks ago and the difference is crazy. Go: Install deps, compile everything done in 5s. Doing the same in Kotlin, laptop freezes,…

Measuring against Kotlin or other languages in this category like Scala is not the right thing to do. Also Kotlin is known for its slow compiler though JetBrains promised that the situation will improve. I would use Scala or Kotlin for everything data but when it comes to low-level networking/infrastructure I wouldn't even touch anything else but Go. Go is in the perfect sweet spot for this task. The Goldilocks Zone of network programming.

Re: A Proposal for Adding Generics to Go

#36
post #26

We have a very large Go codebase here at Stream and not having generics is just not really as big of an issue as you think it is. There are plenty of work arounds if you get used to not having generics in the language. The fast compile times of Go are amazing. I was doing some Kotlin a few weeks ago and the difference is crazy. Go: Install deps, compile everything done in 5s. Doing the same in Kotlin, laptop freezes,…

This is not the first time I argue this case, but I would go a step further and say that not having generics is feature of Go. There are plenty of languages out there with Generics. I use several of them. I use Go when that suits me, and it's typically for cases where high readability trumps doing a lot of magic with generics. I think only once or twice have I thought to myself, "this would have been better with Gene…

The introduction of generics would not change your workflow though. You could still happily "not use it" and keep matters readable. Others who wanted it, would use it.

Re: A Proposal for Adding Generics to Go

#37
post #31

Earlier quoted context omitted.

Why? C isn't type-safe.

And that's (part of) why C needs to go.

Sure. But why not replace it with something that is type-safe AND already has generics, like Rust? Why are we trying to get a do-over on Go?

Re: A Proposal for Adding Generics to Go

#39

Earlier quoted context omitted.

Any successor to C needs to be type-safe. Generics make that easier.

Why? C isn't type-safe.

I think that's the point, the argument is that a "new" language needs (at least) type safety to successfully dethrone C

Re: A Proposal for Adding Generics to Go

#40
post #2

How many different proposals for generics have there been?

It's very good to witness the journey of generic, how the team is very cautious and dedicated to bring Go way of perfection.

IMO This is something that can't be done by a committee of so called industry players.

Post reply on HN