News for hackers. Stuff that matters.
Re:Go generics are not bad by kaba0 on Saturday July 09, 2022 @01:05AM (#32031903)
Some more context would be appreciated on why you think that Java generics are awful?
Re:Go generics are not bad by tsimionescu on Saturday July 09, 2022 @01:52AM (#32032209)
The context is what was said above: Java generics can't abstract over primitive types, they only work for objects. That is awful, and it is important, because this one limitation is the only thing that makes the implementation of generics in Java possible and simple.

If generics had had to actually support ArrayList<int>, they would have required significant changes to how ArrayList is stored in memory, and to how a lot functions which work with generic types are actually compiled. Instead, Java has the easy path in the implementation: since everything only works with reference types, there's no need for multiple copies of a function to work with different types.

Of course, this means that sum<Integer>(new Integer[1000000]) is going to be orders of magnitude slower than sumInts(new int[1000000]).

Re:Go generics are not bad by kaba0 on Saturday July 09, 2022 @02:00AM (#32032270)
It is unfortunate, but that was the only way Generics could ship at the time in a backwards compatible way. But I don’t think it is fair to call it awful, especially knowing the context. Also, when it does show up as a performance bottleneck, it is trivial to fix.