News for hackers. Stuff that matters.
Re:Generics enabled by default in Go tip by brundolf on Saturday August 21, 2021 @02:04AM (#28254624)
Go has some "special" built in functions like len() that work across different structures. What if instead of adding generics they added more of those special functions for working with slices as you describe? Would that have solved your problem?
Re:Generics enabled by default in Go tip by Fire-Dragon-DoL on Saturday August 21, 2021 @02:07AM (#28254635)
Of course, but remember that `len` has constant return type, while in case of slices you'd have a return type that's different on the input slice
Re:Generics enabled by default in Go tip by brundolf on Saturday August 21, 2021 @02:08AM (#28254641)
I see. I guess I assumed that the category of special "privileged functions" would have their powers extend to cover stuff like that (I haven't used Go, I'm just going off of what I've read)

I'm very intrigued by the no-generics idea, so I'm prodding at what might've made it workable enough that this reversal wouldn't be necessary :)

Re:Generics enabled by default in Go tip by Fire-Dragon-DoL on Saturday August 21, 2021 @02:21AM (#28254711)
All good!

Well in Go the assumption is that you jump to interface{} (equivalent to Object in Java or void* in C) when you start having these kind of problems, but there is a performance penalty in doing that, which shouldn't be there if generics are present (and makes the code DRAMMATICALLY worse with all the casting)