News for hackers. Stuff that matters.
Re:Generics enabled by default in Go tip by vorpalhex on Saturday August 21, 2021 @12:47AM (#28254283)
Without generics, I have seen terrible and unreadable golang code. There is no tool that can not be mis-used.

Generics are adding a tool to the toolbox. They can be used well or they can be mis-used. I recently wrote a gui app in Golang using Fyne and I really wish I'd had generics for some of the UI handling - instead I ended up having to write some really ugly and not simple code to handle the case. The end result was worse and less-simple than if I had been able to use generics.

Re:Generics enabled by default in Go tip by jshen on Saturday August 21, 2021 @12:54AM (#28254318)
Can you give an example of terrible unreadable go code due to a lack of generics? I’ve grown to love go because it’s one of the few languages where I can jump into a new code base and relatively easily understand what is going on.
Re:Generics enabled by default in Go tip by kmm01 on Saturday August 21, 2021 @01:58AM (#28254601)
Because you will already have seen that precise piece of code in a thousand other contexts?
Re:Generics enabled by default in Go tip by dmitriid on Saturday August 21, 2021 @04:11AM (#28255159)
> Can you give an example of terrible unreadable go code due to a lack of generic

https://news.ycombinator.com/item?id=28254411

The "solution" to this is copy-pasted boilerplate code with casting for every call.

Re:Generics enabled by default in Go tip by theshrike79 on Saturday August 21, 2021 @01:20AM (#28254443)
I have seen terrible and unreadable generic code, people building abstractions just for the sake of abstractions.

Hello-world level projects with 20 class deep hierarchies of generic classes, just to make it "generic" in case you need it later.

Re:Generics enabled by default in Go tip by doctor_eval on Saturday August 21, 2021 @02:28AM (#28254747)
I agree. It’s true for all languages. I once had to untangle a small Java app that had about five packages with two classes per package (I refactored it into a single package).

Some people will abuse generics, no doubt, just like my colleague abused packages. But Go has such a strong culture around idiomatic code that I’m not too worried that generics are the end of the world. In fact, I don’t like keywords like “append” and I’m hopeful generics will replace them.

TBH I was more upset about the Go 1.17 ability to panic during a type conversion from slice to array pointer. That one really grates my gears.