News for hackers. Stuff that matters.
Re:Generics in Go with Ian Lance Taylor (2019) by esrauch on Tuesday February 18, 2020 @09:11PM (#22362495)
> Is this really an issue with Java's type system though? If you get an ArrayList<Number> and you assume that it contains only whole numbers, that's on you.

The point is that you have an List<Integer> are you allowed to call a function that takes an List<Number>? The answer is effectively "yes it should be allowed" if its not mutating the List (all Integers can be safely read as Numbers) but no if the List is mutable (you can't handle the fact that it might insert a non-Integer number into the Integer-only List).

Re:Generics in Go with Ian Lance Taylor (2019) by joshuamorton on Tuesday February 18, 2020 @10:55PM (#22362923)
This is less LSP and more the co/contravariance of container types, which is its own special hell.
Re:Generics in Go with Ian Lance Taylor (2019) by LessDmesg on Wednesday February 19, 2020 @01:18AM (#22363463)
The hell stems from inheritance, which is just syntactic sugar over composition. And a very unhealthy kind of sugar as that: problems with co- and contravariance, problems with copying, the need for redundant type declarations. And inheritance doesn't guarantee autofulfillment of the Liskov principle, either. One might even wonder why inheritance is needed at all in a language. Go and Rust are certainly fine without it.
Re:Generics in Go with Ian Lance Taylor (2019) by hinkley on Wednesday February 19, 2020 @01:27PM (#22368425)
One of the humblest smart guys I worked with years ago would try to convince me over lunch that the Next Big Language would have syntactic sugar to make composition as easy as inheritance. I think in part because I had intimated that I was trying to create a language (narrator: he didn't. It went nowhere)

There are a couple languages that have added something like this in the interim, but nobody seems to have made it an idiomatic thing. Which is a shame, because I still think I might like to work in the world he dreamed up.

You get a little more composition in languages like NodeJS for the very pragmatic reason that inheritance, at least historically, was not seamless and hence had a high degree of friction.

Re:Generics in Go with Ian Lance Taylor (2019) by pjmlp on Thursday February 20, 2020 @02:53AM (#22373462)
Ah, just like VB did with COM....
Re:Generics in Go with Ian Lance Taylor (2019) by hinkley on Wednesday February 19, 2020 @04:32AM (#22364157)
With the possible exception of a couple of convenience methods, you can model collections (independently) as a source and sink for elements and avoid having to rely on variance at all. But we treat them as a storehouse of shared state... which ought to be our first warning that things are about to go sideways.

Lots of people get confused by variance. They shouldn’t, but insisting in what people should or shouldn’t do rather than working with how they are is a sure route to frustration.

Re:Generics in Go with Ian Lance Taylor (2019) by NovaX on Wednesday February 19, 2020 @12:30AM (#22363260)
It isn't a problem if you design an API by following the rules (PECS). Use wildcards for method parameters when this is the desired behavior. It is not hard to do things right.

https://howtodoinjava.com/java/generics/java-generics-what-i...

Re:Generics in Go with Ian Lance Taylor (2019) by yarg on Wednesday February 19, 2020 @03:34AM (#22363936)
void doThings(List<? extends Number> values){ ... }

This is catered for.