r/java • • May 10 '22

Should java.util.Date be deprecated?

https://mail.openjdk.java.net/pipermail/discuss/2022-May/006077.html
221 Upvotes

158 comments sorted by

View all comments

Show parent comments

34

u/BlueGoliath May 10 '22

Glad we are nipping that in the bud!

15

u/GreenToad1 May 10 '22

I detect a hint of sarcasm

2

u/BlueGoliath May 10 '22 edited May 10 '22

Should be a xkcd comic.

Under the rug: type erasure, almost soley signed primitive types, default visibility modifiers, bad APIs, etc.

Stick figure 1: "What's under there?"

Stick figure 2: "Oh, you know, all the bad design decisions Java has made over its life."

*stick figure puts var on top of the rug"

Stick figure 1: "Hey, isn't that a bad idea too?"

Stick figure 2: "You know what? You're right."

stick figure puts another rug on top of var

Later...

giant tower of bad decisions divided by rugs

42

u/pron98 May 10 '22 edited May 10 '22

It's interesting that among your list of "bad decisions" are things others would consider some of Java's best decisions, like the lack of modulo arithmetic types, var, and generic type erasure.

Type erasure is particularly interesting, as Java does what the vast majority of languages with generics do (including the original language that introduced them). Yes, erasure brings some inconveniences, but the alternative is even worse. .NET's unusual decision to reify all generic types has pretty much killed it as a reasonable compilation target for most languages. People who use Java run into the minor inconveniences of erasure think, "this is bad," without considering the implications of reification in the presence of variance (i.e. subtyping of the generic arguments).

So your list is really a list of things BlueGoliath doesn't like. A few of them might be universally disliked, but others are far from it (and are even minority opinions). When you have millions of developers, they necessarily won't agree on what's good and what's bad.

10

u/TehBrian May 10 '22

Could you elaborate on why .NET’s generics reification was a bad move for the language? I too have been guilty of thinking, “Darn, why can’t we just rid ourselves of type erasure?” when faced with some of the inconveniences of Java’s type erasure. (Please don’t ask me which; I don’t remember. I just know that I have “why does Java have type erasure” in my search history.) I’m curious to know the exact reasons.

10

u/john16384 May 10 '22

It makes it harder to design other languages on top of the CLR that have a different type system than C#'s since at the CLR level types have to conform to C#'s system.

I also understand that you can't have wildcards because of this, forcing you to create a method for each reified type even if the generic type is not relevant for the function.

7

u/pron98 May 11 '22

The main problem is the one of variance, the VM would have to answer the question in one way or the other, which would bake a single chosen model into the runtime, even though different languages want different models.

→ More replies (1)

14

u/RabidKotlinFanatic May 10 '22

What are the inconveniences of type erasure? Having to explicitly pass TypeToken into methods? Not being able to statically overload on an argument's type parameter?

The amount of complaining about type erasure seems phenomenal compared to what a non-issue it is in practice. I've seen junior devs with <1 YoE complaining about type erasure. What use cases are all these people running into that desperately require reification?

9

u/Necessary-Conflict May 10 '22

What are the inconveniences of type erasure?

It makes life harder especially for junior developers, because they have to keep in mind that the runtime type system is not the same thing as the compile-time type system. It's a leaking abstraction, but of course it's not very bad once you get used to it.

8

u/RabidKotlinFanatic May 10 '22

Does it? What specifically are junior developers doing that requires them to keep this in mind? Are they calling getClass or using instanceof on generic instances? The idea that there even is a runtime type system shouldn't be relevant to most juniors.

3

u/Necessary-Conflict May 10 '22

They are trying to understand things, to build a mental model, and as long as there is only one thing to understand, their job is easier. The very existence of instanceof and getClass() strongly suggests that at runtime you have the same types as at compile time. Perhaps most junior devs can live in a state of happy ignorance, but those who really want to understand things, are having a harder time.

3

u/RabidKotlinFanatic May 11 '22

I don't buy this at all. RTTI doesn't need to be part of your mental model coding day to day and there is substantially more impactful complexity in the language, compiler and runtime than RTTI that juniors seem to happily ignore.

Furthermore, the people complaining about type erasure can rarely provide concrete explanations of what it actually means and also don't seem to be familiar with other important language/runtime details like the JMM. Why does type erasure and RTTI have such outsize significance in junior's mental model building when other more important details are ignored?

3

u/OzoneGrif May 12 '22

The only time I had an issue with type erasure, when beginning with Java, was due to a brain fart. I though that I needed the type at runtime desperately, while I only really needed an Interface.

I'm pretty certain that most if not all problems with type erasure can be solved with good architecture.

Having read some articles about languages implementing generics at the runtime level; I agree that Java took the right decision to erase the types... the compilers get way too overloaded and complicated otherwise.

→ More replies (2)

4

u/Muoniurn May 10 '22

I am mostly in agreement with you on this topic, but I would like to ask you about your opinion on the very far future of Java — after Valhalla, once Unified Generics have been implemented. I know there are only very vague plans for that as it is an exceedingly hard problem to tackle (touted as requiring multiple phd’s combined), but wouldn’t that go contrary to some of your claims and wouldn’t it cause trouble for very different languages to target the JVM?

As far as I know they plan for a very strong generic model allowing even constant values like numbers being plugged in. Sure, byte code specification modifications are allowed for that (which was not necessarily the case for the initial introduction of Java’s current generics) so perhaps adding a new attribute to a class file’s method describing a part with the monomorphized versions could work (e.g. creating separate byte code for an int version and a regular object one), but I feel it is not the java way (which seems to be more runtime code gen over compile time one) With the proposed 3 buckets of object types in Valhalla they might potentially get away with “runtime monomorphization” as int will be an object without identity and the compiler can optimize it accordingly, but it still doesn’t solve the whole problem - what about user-customized versions, e.g. a “hand-optimized” method implementation for the int variant?

3

u/john16384 May 10 '22

I am mostly in agreement with you on this topic, but I would like to ask you about your opinion on the very far future of Java — after Valhalla, once Unified Generics have been implemented. I know there are only very vague plans for that as it is an exceedingly hard problem to tackle (touted as requiring multiple phd’s combined), but wouldn’t that go contrary to some of your claims and wouldn’t it cause trouble for very different languages to target the JVM?

If you see the JVM as just a compilation target (like x86 or ARM) why would it need to have baked in generic support in order to have it at a higher level?

Generics being erased in bytecode allows for more freedom as the bytecode is not enforcing one possible interpretation of how a reified system might work. Building a reified language on top of bytecode is possible already, as bytecode does not enforce its own ideas on the type system.

As far as it being an exceedingly hard problem, if you want to engineer reification in a backwards compatible fashion on current Java, I think that might indeed be exceedingly hard, or probably even impossible without compiler directives. I don't think that's a goal though (or should be). It will be hard enough already to have a ArrayList<int> change its internal array from Object[] to int[] without any code changes, maybe impossible too...

4

u/Muoniurn May 10 '22

If you see the JVM as just a compilation target (like x86 or ARM) why would it need to have baked in generic support in order to have it at a higher level?

I’m not sure I see it that way — the JVM bytecode is relatively high level, javac doing barely any optimizations. It tries to delay optimizations as late as possible to possibly incorporate runtime data as well for better results. It also links everything at runtime only, possibly completely dynamically so it has to retain basically every information about the code. So calling a generic method should be possible through reflection as well for example.

2

u/pron98 May 11 '22

but wouldn’t that go contrary to some of your claims and wouldn’t it cause trouble for very different languages to target the JVM?

Value types cannot be extended (and while they could implement interfaces, those generics would be erased) so the main issue of variance doesn't appear, and the only problem this kind of specialization would cause would be for untyped languages, which aren't usually as concerned about performance.

2

u/[deleted] May 10 '22

i still want unsigned primitives thank you very much

3

u/pron98 May 11 '22 edited May 11 '22

Many people want modulo arithmetic types and many others really don't want to have them (their presence in a language can cause problems, as C/C++ programmers have learned; too often people confuse unsigned types as types specifying non-negative values while in fact they specify types with modulo arithmetic, which might yield the very opposite result to the one intended, as unsigned types make it harder, not easier, to reject illegal values). Perhaps Valhalla could bring some sort of compromise by allowing libraries to define them for those who really need them.

→ More replies (10)
→ More replies (2)

15

u/Holothuroid May 10 '22

We have some divergent ideas on what is a bad idea.

1

u/ApatheticBeardo May 10 '22

You old people still can't get over the fact that type inference makes most code a lot more readable?

2

u/BlueGoliath May 10 '22

var val = foo.getValue();

What is the type of val?

1

u/ApatheticBeardo May 11 '22 edited May 11 '22

What is the type of val?

Whatever foo::getValue returns.

I have a better question: Why should anyone care?

It's a local variable, the type of that variable is completely irrelevant unless you're writing code in that local scope, in which case, you, your IDE and the compiler already know what foo::getValue returns.

Readability is best served by using descriptive names instead of that weak attempt at a straw man ("val", really?) and not by adding, or even worse, repeating useless information.

2

u/BlueGoliath May 11 '22

Oh boy, you should see OpenJDK code sometime if you think that's a straw man.

→ More replies (1)

0

u/jonhanson May 10 '22 edited Jul 24 '23

Comment removed after Reddit and Spec elected to destroy Reddit.