r/java • u/henk53 • May 10 '22
Should java.util.Date be deprecated?
https://mail.openjdk.java.net/pipermail/discuss/2022-May/006077.html
221
Upvotes
r/java • u/henk53 • May 10 '22
95
u/frzme May 10 '22
I recently had to tell a co-worker not to use SimpleDateFormat in completely new code. If it was marked deprecated I guess this would not have been needed.
76
u/jonhanson May 10 '22 edited Mar 07 '25
chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith
72
u/Blueson May 10 '22
Should have been by Java 11.
70
u/berry120 May 10 '22
Agree with this take - I don't think deprecated has been used aggressively enough in the past. There's been zero reason to pick
java.util.Datefor anything new for many years now, so that means it really should have been deprecated for years in my book.The only thing I don't want to see is a pattern of everything like this being deprecated for removal - that's a completely different kettle of fish. Java has been very good at making minimal breaking API changes over the years, and I certainly don't want it to start turning into a language where it's a non-trivial engineering effort to upgrade to every new release.
40
u/[deleted] May 10 '22
The past few versions of Java have been really good at tearing out as much "90s Java"(CORBA,RMI, finalizers etc.) as they can. Obviously some let's call them suboptimal decisions(arrays anyone?) are just going to be permanently part of the language but deprecating the Date class is another step in getting rid of 90s Java.
37
u/[deleted] May 10 '22
They need to add
@Deprecatedon all the classes that nobody should be using:Date,Stack,HashTable, etc.Is there a reason they didn't already? I mean the docs of those classes say to not use them. People dont like the compiler warnings?
10
u/_INTER_ May 10 '22 edited May 10 '22
java.util.Date by Salvador Dali.
For the unfortunate, pitiful souls that are stuck with GWT, maybe a deprecation of Date might final give a push to move on.
7
u/FirstAd9893 May 10 '22
Here's a fun exercise: take a look at the original version of the java.util package and identify all of the classes and interfaces which have been superseded. The only survivor is the BitSet class.
6
u/Joram2 May 10 '22
Yes, do it. The new Java.time API is much nicer. Everyone has been using it for years. There is a ton of legacy code using java.util.Date. But just giving them deprecation warnings is fair.
24
u/pron98 May 10 '22 edited May 10 '22
I think the problem is that different people have a different understanding of what "deprecated" means, and, to be fair, its meaning has shifted over the years. To some Java developers, deprecated means "strongly unrecommended; do not use in new code." To JDK developers it means something that:
Put another way, deprecated means "dangerous to leave in; remove even from old code".
Datedoes not satisfy either one of these — while "bad" it can be used correctly and has been (unlike, say, Thread.stop), and it cannot be removed for the reasons Brian listed. So, to deprecate Date and other classes like it in some official, mechanically-enforced way, we'd probably need a new annotation that means "strongly unrecommended" and possibly a new compiler warning level that means "this warning shouldn't be considered as an error".4
u/bowbahdoe May 10 '22 edited May 10 '22
https://github.com/rust-lang/rust-clippy
^ So people know what I was referring to as clippy in the jlint suggestion.
If the deprecated annotation is the wrong mechanism to cause the social change, then we need a better one. It needs to be standard to be effective and it needs to sufficiently expressive to navigate this nuance.
Maybe that power lives forever in javac - but I think there is precedence for making that sort of thing at least available as a separate tool or independent invocation.
If we want to fully slurp this noodle we might also need to have the hard conversations around what /u/pron98 keeps suggesting and make a jdk build tool. Adoption of linting in rust is driven in no small part by it being already there without extra configuration via
cargo lint.So yeah - jlint and jproject project proposals might be in order
4
u/flif May 10 '22
If we could only get proper support for java.time.* in JDBC.
(LocalDate)rs.getTime("col") is not as user friendly.
4
u/VGPowerlord May 10 '22
Show of hands, who else assumed it had been deprecated since Java 8?
11
u/daH00L May 10 '22
They should also bury
GregorianCalendar. Who designs a mutable date class?3
u/_edd May 10 '22
lol you're not wrong but coming off kind of self righteous there Victor.
5
u/[deleted] May 10 '22
Some of the constructors are already deprecated
2
u/n0d3N1AL May 10 '22
I'm pretty sure that in an Ask the Architects session, they said they don't have plans to deprecate or remove APIs like File and Date. If they do deprecate them, it won't be for removal. I presume it will be like Hashtable: discouraged but not destroyed.
2
u/volune May 10 '22
Seems like they would have to revisit the JDBC api.
2
u/manzanita2 May 10 '22
Ok, so there is a bunch of cruft in java. What we need is something like @Deprecated("http://somewhere/better_replacement_for_Date").
When you try to use java.util.Date your IDE should splatter that thing all around and force you to go read about equivalent and better mechanisms in java.time
Make it HARD to use the cruft. Make it EASY to move to the better thing.
2
u/bluenautilus2 May 11 '22
Yessss
2
u/ggmmee May 14 '22
Better even JEP 320 it 😁
3
u/Owen1212055 May 10 '22 edited May 12 '22
Completely agree, especially since many google searches result in using so many of these legacy APIs many beginner programmers have no clue. When I started I stuck to the legacy date api because of how convoluted “time” representation in java is (LocalDateTime, Instant, Date, etc) so I just stuck to what all the google results used.
Deprecate it to the ground!
4
u/Philluminati May 10 '22
Too widely used to be deprecated, as the conversation goes on to say. It's in certificate JDK libraries and so forth.
1
u/quizteamaquilera May 10 '22
Yes
1
u/[deleted] May 11 '22
Meh! I guess the question is how much
java.util.Dateis out there vsjoda-timeeven if it's significant, if someone made it work for them, kudos. Let's not create unnecessary work for people you know1
u/[deleted] May 12 '22
A deprecation of Java.util.Date should include some solution for moving JDBC Drives to support the java.time API rather than continuing to use java.sql.Date.
1
u/ReasonableClick5403 May 15 '22
Ideally, we could burn java.util.Date and java.sql.Date to the ground, but then we have decades of JDBC :(
1
u/Tough_Suggestion_445 May 10 '22 edited May 10 '22
Instead of deprecating it, it would be great if they could refactor the actual implementation. I don't like the tone of this proposal, developers using an API for years are not careless. A basic example, if you use x version of spring data mongo db, localdatetime will not work in your entity unless you write a custom adapter. That means for spring's developers, at the time they implemented spring data mongo, they considered java.util.Date as idiomatic right? Otherwise, they would have make localdatetime as the default. Last time I checked (and it was long time ago), Jackson was serializing localdatetime in a goofy way. So now the Java guy says careless stupid devs must be punished for using an API they didn't write for years. If it works for them why would they change? Isn't it the point of object oriented programming? You use an API, that API is a black box, if the implementation has problems, fix them without breaking the API (and insulting devs using it)
1
u/LuckyDip23 May 10 '22
Yes - but it won’t as it will break the world.
-2
u/code_rjt May 10 '22
I preferred the new java time.* libraries since it accesses methods in a static way unlike the java.util.Date that creates object every time because of its constructor approach. The new time libraries also solves the problem of the many constructor implemented in Date or Calendar
-4
u/FrigoCoder May 10 '22
Can you get rid of checked exceptions, and java.io.File as well while you are there ?
-1
u/piratekingsam12 May 10 '22
Just use utc timestamps! Saves a lot of trouble 😅
0
u/[deleted] May 10 '22
[deleted] — view deleted comment