News for hackers. Stuff that matters.
Re:Go generics may use square brackets [] not parenthesis () by shirro on Tuesday July 14, 2020 @10:37PM (#23840591)
I really like the Go standard libraries. I can do most of what I need with them. I worry some of the people calling for generics will move the language in the direction of massive abstract libraries. I don't want to include a Go version of Boost in everything I build. Complicated type signatures seem like an unnecessary additional burden for average programmers.

I really hope generics, like reflection, are only used when there isn't a simpler option. I honestly would have preferred and had more use for sum types.

I like the square brackets though. They look right for Go and it is more readable.

Re:Go generics may use square brackets [] not parenthesis () by _bxg1 on Tuesday July 14, 2020 @11:02PM (#23840749)
I haven't used Go but I'm curious, how do core data structures like hash maps work without generics? Does everyone just roll their own for their particular use-case?
Re:Go generics may use square brackets [] not parenthesis () by meditative on Tuesday July 14, 2020 @11:16PM (#23840828)
> how do core data structures like hash maps work without generics

blessed implementations inside the language, slices, maps and channels are built in generics.

sync.Map is what the standard library version looks like. It loses type safety.

https://golang.org/pkg/sync/#Map

Re:Go generics may use square brackets [] not parenthesis () by echlebek on Wednesday July 15, 2020 @02:32AM (#23842018)
I'm looking forward to seeing these types of libraries improve with generics. It's notably more work to use these data structures, even if they are used rarely.
Re:Go generics may use square brackets [] not parenthesis () by shirro on Tuesday July 14, 2020 @11:17PM (#23840842)
Go cheats with some built-in generic types. So you can declare a hashtable as a map of any comparable type to any other type. But yes you typically have to implement things yourself for more complex cases so that does limit the sorts of libraries that are available and the way you write programs.
Re:Go generics may use square brackets [] not parenthesis () by erik_seaberg on Tuesday July 14, 2020 @11:53PM (#23841129)
Unfortunately "comparable" is not an interface, and the default implementation (which you can't opt out of) sometimes panics.
Re:Go generics may use square brackets [] not parenthesis () by pjmlp on Wednesday July 15, 2020 @08:18AM (#23844117)
Like in everything Go, you opt out by using a clever hack like having a nameless non comparable field in the struct. Oh yeah.
Re:Go generics may use square brackets [] not parenthesis () by echlebek on Wednesday July 15, 2020 @02:29AM (#23842001)
The built-in types map, chan, array, and slice take type parameters, and they are usually sufficient for doing whatever you need to do.

It's incredibly great that, generally speaking, if I'm looking at Go code, the only kind of hashtable there can possibly be is the Go map data structure. The only kind of blocking queue there can possibly be is the Go chan data structure.

You will never see a LinkedTreeDeque or whatever other bizarre concoction someone might come up with. And people don't feel obligated to make every API an iterator of some kind.

Go makes being generics architecture astronautics impossible, and I really love that about it. Perhaps that makes me basic, but I am basic and happy.

Re:Go generics may use square brackets [] not parenthesis () by throw_m239339 on Wednesday July 15, 2020 @10:26AM (#23845614)
> The built-in types map, chan, array, and slice take type parameters, and they are usually sufficient for doing whatever you need to do.

They are so sufficient you need to learn all these tricks by heart in order to do basic operations on slices:

https://github.com/golang/go/wiki/SliceTricks

Re:Go generics may use square brackets [] not parenthesis () by jfkebwjsbx on Wednesday July 15, 2020 @09:45AM (#23845103)
A lot of software needs specialized data structures to perform their job.

They are not "bizarre concoctions".