News for hackers. Stuff that matters.
Re:Go generics proposal moves to “likely accept” by Crash0v3rid3 on Wednesday February 03, 2021 @04:32PM (#26019418)
I've been writing Go for years and never came across a problem that made me want to have generics.

Anyone able to give me a simple example demonstrating why Go needs this?

Re:Go generics proposal moves to “likely accept” by jacques_chester on Wednesday February 03, 2021 @04:36PM (#26019478)
It depends on how you define "need". Golang could be replaced with a notation for NAND gates and still be able to "do" everything it does now.

Yesterday I was in a pairing interview where I debugged and sped up some code. All-in-all I wound up with about 200 lines or so of Golang, including a lot of "yes, another loop" code. All I was doing, really, was mapping, forking and joining.

Meanwhile in Java, I could have gotten most of this in about 20 lines withJava 8 Streams and .parallel(). Generics make that tractable.

[dead]
Re:Go generics proposal moves to “likely accept” by jacques_chester on Wednesday February 03, 2021 @05:22PM (#26019961)
No, I had chosen Go for that problem. My reasoning was that most of the code I've read or written in the past 2 years has been Go, so it seemed like I should focus on using a language where I was warmest.

But in retrospect I would have preferred Java. That's my fault.

Re:Go generics proposal moves to “likely accept” by bcrosby95 on Wednesday February 03, 2021 @05:34PM (#26020098)
If you did, I wonder if you would regret choosing Java over Go for other reasons. I tend to find that no matter what language I choose, there's some parts of the code that I would prefer to be able to write in a different language.
Re:Go generics proposal moves to “likely accept” by jacques_chester on Wednesday February 03, 2021 @06:06PM (#26020447)
> I tend to find that no matter what language I choose, there's some parts of the code that I would prefer to be able to write in a different language.

There is no final nirvana language. That is the awful truth of existence.

Re:Go generics proposal moves to “likely accept” by jklehm on Wednesday February 03, 2021 @08:22PM (#26021458)
> no final nirvana language.

There isn't one...yet!

Re:Go generics proposal moves to “likely accept” by bobthebuilders on Wednesday February 03, 2021 @04:54PM (#26019666)
Perhaps their existing codebase is in Go and they need to use a utility. Perhaps they really like the performance of Go compared to Java. Perhaps they can't just use Java because of inertia or that no one else knows Java. Languages have warts, and wanting to remove one is not a bad idea.
Re:Go generics proposal moves to “likely accept” by 13415 on Wednesday February 03, 2021 @04:43PM (#26019558)
I've seen so many abuses of interface{} in packages, especially for containers, that anything that can alleviate this problem is a step in the right direction. Even when they are not strictly necessary I expect generics to improve a number of packages. Then there is also the potential performance benefit, since generics should be strictly compile-time features - at least I hope that's the case for Go, I haven't checked the details of the proposal.
Re:Go generics proposal moves to “likely accept” by Gibbon1 on Wednesday February 03, 2021 @05:52PM (#26020302)
Dumb question, if you change an interface{} in go do you have to change everything based on it?
Re:Go generics proposal moves to “likely accept” by tptacek on Wednesday February 03, 2021 @04:34PM (#26019436)
Presumably anything you've used codegen to solve; for instance, it'll probably make SQL libraries a lot nicer to use.
Re:Go generics proposal moves to “likely accept” by paedubucher on Wednesday February 03, 2021 @04:37PM (#26019490)
Code generation requires an additional build step. One thing I like about Go is that it feels like a scripting language (go run).

I guess writing a numeric library, like Python's NumPy, is a lot more convenient using generics. But I've never tried...

Re:Go generics proposal moves to “likely accept” by iMerNibor on Wednesday February 03, 2021 @04:38PM (#26019498)
Lack of typed containers is a bit annoying for someone who touches go every now and then
Re:Go generics proposal moves to “likely accept” by gher-shyu3i on Wednesday February 03, 2021 @05:34PM (#26020091)
Containers, operations on streams (map, filter, etc.), optional types (although those need tagged unions, something too advanced for golang), better concurrency handling (e.g. Task types), etc.
Re:Go generics proposal moves to “likely accept” by jimbokun on Wednesday February 03, 2021 @05:07PM (#26019796)
Proper higher level functions like map, reduce, ...
Re:Go generics proposal moves to “likely accept” by tptacek on Wednesday February 03, 2021 @06:36PM (#26020712)
Oh, wow, you're right. OK, that'd be a huge win.
Re:Go generics proposal moves to “likely accept” by kasey_junk on Wednesday February 03, 2021 @07:21PM (#26021057)
This is what I assumed generics were for. I haven’t been paying attention to the proposals but given the existing golang generics don’t support proper variance should I expect it with the user defined variance?
Re:Go generics proposal moves to “likely accept” by wyufro on Wednesday February 03, 2021 @05:14PM (#26019873)
I wrote an Entity-Container system that really could've benefitted from a generic Get function. Instead I had to write on for each entity-type, even though they were the same except for different types.

Most places where the empty's interface is used now could benefit from it. Eg. the json package could state it always uses float64 for numbers (except when you tell it to use Number).

Re:Go generics proposal moves to “likely accept” by eweise on Wednesday February 03, 2021 @04:42PM (#26019545)
One example would be to return a single value from a method containing Either the value you want, or the error. That way you could chain a bunch of method calls together and just check for errors at the end instead of checking after each method call.