News for hackers. Stuff that matters.
[dead]
Re:Why Generics? by dang on Wednesday July 31, 2019 @10:35PM (#20580702)
Oh dear. Personal attacks are not ok on HN, regardless of whom you're attacking. Please stick to the site guidelines, no matter how passionately you feel about the Liskov Substitution Principle.

https://news.ycombinator.com/newsguidelines.html

You obviously have a good point to make, but it needs to be done without firebombs.

Re:Why Generics? by rsc on Wednesday July 31, 2019 @04:47PM (#20578367)
> Rot in hell forever, Josh. And take your Effective Java with you to throw on the pyre.

Well that seems uncalled for.

Re:Why Generics? by hinkley on Wednesday July 31, 2019 @06:54PM (#20579450)
It’s fairly difficult to come to terms with an “everything was going pretty well until...” moment and doubly so when it can be personified.

Once we broke LSP, a cascade of similar ideas started showing up with regularity, especially in J2EE. I used to be able to go on at some length but now it’s more “I hope I never meet this guy because it’ll be awkward as hell.”

Re:Why Generics? by ben509 on Wednesday July 31, 2019 @05:56PM (#20578967)
> The only truly unforgiveable one is UnsupportedOperationException. The guy who wrote the collections API for Java didn't know the first thing about the Liskov Substitution Principle, and gave the world an implementation that violates it...

The implementation perfectly follows it because the LSP simply requires identical behavior, and the contract clearly states it may[1] throw an exception. All the implementations "may" throw an exception. Sorry, but they correctly lawyered the LSP.

> I came up with around 20% more than the selected design.

But `add` can throw 5 different exceptions depending on restrictions your implementation wants to place on a given collection, does it allow for all that? In terms of making an interface that was small and reusable by many projects, runtime exceptions are a pretty good compromise for a standard library.

[1]: https://docs.oracle.com/javase/7/docs/api/java/util/Collecti...

Re:Why Generics? by hinkley on Wednesday July 31, 2019 @06:48PM (#20579405)
No they most definitely are not. One implementation receives a message. The other categorically rejects it. I cannot substitute them.
Re:Why Generics? by ben509 on Thursday August 01, 2019 @10:32PM (#20590306)
Yes, those are the same behavior. Both of them "may" accept it and "may" reject it, and "may" includes both "always" and "never".

It is correct to the letter of LSP, but not the spirit of it, and this was a conscious decision; contrary to your original claim, they understood the principle perfectly well.

Re:Why Generics? by extempore on Wednesday July 31, 2019 @04:11PM (#20577965)
Of course they do. Not sure why it’s something to brag about or not to brag about though, it’s an implementation detail. Scala for instance uses custom classes for each size set up to a certain threshold.