Re:Constraints in Go
by cherryteastain on Sunday November 17, 2024 @06:21AM
(#42163502)
I think a lot of the people who wanted generics wanted them more to be like C++ templates, with compile time duck typing. Go maintainers were unwilling to go that route because of complexity. However, as a result, any time I think "oh this looks like it could be made generic" I fall into a rabbit hole regarding what Go generics do and dont allow you to do and usually end up copy pasting code instead.
[ Parent
| on HN ]
I think "oh this looks like it could be made generic" is the wrong time to convert to generics.
You should convert when you reach the point "I wish I had that code but with this other type". Even then, sometimes interfaces are the right answer, rather than generics.
I would say it's when you're looking at a profile of your program and notice that you're bottlenecked on interface{} things.
People complain about casting interface{} and type safety but I've probably written hundreds of thousands of lines of Go over many years and I can't remember ever seeing a bug from that. You do it once, in one place, and never think about it again.
Re:Constraints in Go
by cherryteastain on Sunday November 17, 2024 @03:56PM
(#42167163)
I mostly agree, hence the
> end up copy pasting code instead
bit of my original comment