←back to thread

Constraints in Go

(bitfieldconsulting.com)
210 points gus_leonel | 1 comments | | HN request time: 0.2s | source
Show context
indulona ◴[] No.42163167[source]
i have been writing Go exclusively for 5+ years and to this day i use generics only in a dedicated library that works with arrays(slices in Go world) and provides basic functionality like pop, push, shift, reverse, filter and so on.

Other than that, generics have not really solved an actual problem for me in the real world. Nice to have, but too mush fuss about nothing relevant.

replies(10): >>42163189 #>>42163244 #>>42163415 #>>42163694 #>>42163834 #>>42164296 #>>42164983 #>>42165141 #>>42165270 #>>42165680 #
tonyedgecombe ◴[] No.42163415[source]
I sometimes wonder if they should have implemented generics. On the one hand you had a group of people using go as it was and presumably mostly happy with the lack of generics. On the other side you have people (like me) complaining about the lack of generics but who were unlikely to use the language once they were added.

It's very subjective but my gut feeling is they probably didn't expand their community much by adding generics to the language.

replies(5): >>42163502 #>>42163612 #>>42164299 #>>42169690 #>>42169802 #
cherryteastain ◴[] No.42163502[source]
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.
replies(1): >>42164231 #
wyufro ◴[] No.42164231[source]
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.

replies(2): >>42165199 #>>42167163 #
1. cherryteastain ◴[] No.42167163[source]
I mostly agree, hence the

> end up copy pasting code instead

bit of my original comment