2 ms·
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 f
by brundolf 5y ago
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?
- Fire-Dragon-DoL 5y agoOf 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
- brundolf 5y agoI 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 :)
- Fire-Dragon-DoL 5y agoAll 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)