r/programming • • May 21 '20

Java programming language celebrates 25 years

https://www.infoworld.com/article/3544229/java-programming-language-celebrates-25-years.html
95 Upvotes

73 comments sorted by

View all comments

8

u/backelie May 21 '20

Pre-generics Java was a shit language.

0

u/[deleted] May 21 '20

[deleted]

4

u/Ayfid May 21 '20

Generics are still shit today in Java.

3

u/DetriusXii May 21 '20

Could you explain why they're shit in Java?

4

u/Ayfid May 21 '20

https://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Java#Generics

This is the best comparison of the pros and cons of how Java decided to implement generics vs a sensible way of doing it that I have seen.

Most notably, the comparison table in the "Type erasure versus reified generics" section.

1

u/DetriusXii May 21 '20

See my post to florinp. But it seems that reified generics don't lead to higher kinded types. F# doesn't have them and I can't tell if F* does

2

u/Ayfid May 22 '20 edited May 22 '20

Type erasure vs reification is entirely orthogonal to HKTs.

HKTs are a superset of generics - generics are a limited form of HKTs. Neither type erasure nor reification "lead to" HKTs. They are an implementation detail of generics and both can be built upon to build more expressive forms of HKTs.

Your statement sounds like an argument you have heard elsewhere but don't really understand. It is non sequitur.

Nor does it in any way address any of the numerous problems with erasure, as detailed in the above wiki.

2

u/DetriusXii May 22 '20

Show me a language that has both reified generics and higher kinded types.

2

u/Ayfid May 22 '20

.NET is the only platform that uses reification, and it does have higher kinded types; it has generics, which are HKTs. It does not have the more expressive forms of HKTs (e.g. More expressive type constructors as you find in many functional languages) for many reasons which have nothing at all to do with its types being reified. There are RFC proposals to extend C# with more advanced HKTs and they do not propose making changes to reification - because reification is no impediment to expanding generics.

Rust also has HKTs proposals which also do not require it move away from monomorphisation (which is essentially reification at compile time).

Java does not have HKTs beyond what C# has. It's generics are no more expressive than C#'s.

What point are you trying to make here? You either don't appear to have one, or you have no idea what higher kinded types actually are.

You might as well be demanding that I provide you with flying pigs else you will conclude that unicorns are real. Your demand has no bearing on the topic here.

3

u/florinp May 21 '20

Type erasure at runtime for a language that use parametric polymorphism with runtime support

6

u/DetriusXii May 21 '20

Type erasure at runtime for a language that use parametric polymorphism with runtime support

Haskell has type erasure too. It seems that most languages that want to implement higher kinded types needs to have type erasure. There are no languages with reified types and with higher kinded types.

2

u/flatfinger May 21 '20

What do you mean "higher kinded types"? The .NET framework, and languages targeting it, use reified generics but also support covariant and contravariant generic interfaces.

2

u/DetriusXii May 21 '20

Higher kinded types are generic types that can box other types. Haskell and Scala support higher kinded types whereas .NET only support concrete types. Instead of only being able to pass a function void doSomething<A>(List<A> list) into a function, in Haskell and Scala, a function can be declared as void doSomething<M<_>, A>(M<A> list) where M can be any type of container, including a List<_>.

1

u/kprotty May 21 '20

If I understand that definition of HKT correctly, then could Ziglang be considered as one with reified generics without type erasure?

fn doSomething(comptime M: var, comptime A: type, list: M(A)) void {}

1

u/DetriusXii May 22 '20

If Zig allows that, then you have higher kinded types. I'm not fully sure that zig's types are reified from the examples provided. Are you able to perform a cast of a function parameter into a generic type? C# allows that. Java does not. C# allows bool compare<Q>(object o) { return o instanceof Q; }

→ More replies (0)

1

u/Ayfid May 22 '20 edited May 22 '20

The C# language doesn't allow that, but the runtime can reify such types. You can write code which, at runtime, creates a new realisation of any generic type, and the JIT will reify that and generate all of the relevant code and type metadata. You can then instantiate this new type and call methods on it.

The language does not provide mechanisms to do this, but you can do it with reflection.

Reified generics is not a blocker to type constructors. This functionality is already possible today with reification in the runtime. C# not having it yet is not proof that it is only possible with type erasure.

1

u/florinp May 22 '20

I've said language with parametric polymorphism with runtime support.

Haskell don't need runtime support for that. The same as C++ for example.

Java doesn't have support for higher kinded type so I don't understand your post.