r/programming • u/joesilver70 • May 21 '20
Java programming language celebrates 25 years
https://www.infoworld.com/article/3544229/java-programming-language-celebrates-25-years.html36
28
u/Determinant May 21 '20
A new dinosaur was discovered: All hail the Javasaurus!
In all seriousness, I'm glad that Java is advancing the JVM which other languages like Kotlin really benefit from. If the JVM wouldn't exist then a bunch of other languages that are built on it wouldn't have succeeded.
So as clunky as Java is, it's actually pushing forward state-of-the-art advancements in the JVM.
11
u/dark_mode_everything May 21 '20
It's clunky to write. The bytecode is pretty much the same if not more optimized than Kotlin.
6
u/Determinant May 21 '20
Kotlin does some things during compile time which results in different bytecode.
For example, functions that accept lambdas which are marked with the
inlinemodifier get inlined into each call site. This means that no lambda object gets created which avoids the performance issues from non-local memory access as well as eliminating any garbage collection overhead.There are a ton of other improvements as well. In fact, most Kotlin bytecode can't be decompiled to Java because Kotlin makes use of bytecode capabilities that aren't possible in Java.
1
u/not-enough-failures May 22 '20
That actually causes some problems with some JVM tooling, like until very recently (a couple of days ago) GraalVM would crash on some kotlin coroutine code because it used some type of loop that was assumed to never be emitted by the Java compiler.
Thankfully it's now fixed.
1
u/Determinant May 23 '20 edited May 23 '20
I'm pretty sure that the Graal team said that they just didn't optimize that use-case before whereas it's now faster for coroutines.
Also note that Kotlin-generated bytecode is fully compliant with the JVM bytecode specifications and Graal is supposed to be able to handle all valid bytecode regardless of where it came from.
41
3
8
u/backelie May 21 '20
Pre-generics Java was a shit language.
0
May 21 '20
[deleted]
23
u/MattCubed May 21 '20
ML had parametric polymorphism (what Java calls generics) with full Hindley-Milner type inference in the 70s.
0
May 21 '20
[deleted]
20
u/MattCubed May 21 '20 edited May 21 '20
I wasn't trying to brag about functional programming. I'm just disputing the claim that "generics were shit in 1995".
17
May 21 '20
Yeah, perhaps if the industry had been less obsessed with object oriented XML in the 90's, we wouldn't still be rediscovering 30 year old ideas as if they were new.
1
u/slowpush May 22 '20
They were shit in 1995. The only choices that Java had in terms of actual proposals were absolute garbage.
Arguing about the theoretical "well FP had it" is just circlejerking.
3
u/MattCubed May 22 '20
Ah ok, I misinterpreted "generics were shit in 1995" as "the concept of generics in general was poorly developed in 1995", but it seems you meant "all proposals to add generics to Java were shit in 1995". That seems fair.
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 asvoid 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.
0
u/florinp May 21 '20
Really ? Ada ? Haskell ?
0
May 21 '20
[deleted]
1
u/florinp May 22 '20
" Getting genetics into Java in 95 would be C++ templates. "
Why ?
Also Ada is not a FP language.
P.S. don't downvote a post that you don't agree with (or don't understand).
2
2
9
u/0xC1A May 21 '20
25 years of RAM torture.
28
u/VegetableMonthToGo May 21 '20
Java is better with ram then ever before. It's dubious throne has been taken by Electron
13
May 21 '20
Found the CS1 kid
1
u/not-enough-failures May 22 '20
As a CS kid I can confirm this is how most CS kids act after their first two programming classes.
6
7
1
u/brunocborges May 22 '20
Key Programming Languages older than Java:
C
C++
Lua
Python
Perl
Visual Basic
Haskell
TCL
SmallTalk
Erlang
Object Pascal
Objective-C
MATLAB
COBOL
FORTRAN
Key programming languages of same age:
JavaScript
Ruby
PHP
Rethink Legacy.
-27
0
May 21 '20
[deleted]
10
u/DoListening2 May 21 '20
Have you seen this talk? https://youtu.be/te3OU9fxC8U
They have a lot of stuff planned. Although they are heavily constrained in what they can/cannot do by backwards compatibility.
2
u/nutrecht May 22 '20
Unfortunately the main killer feature, null-safety, is not planned because there's no good way to do that without breaking compatibility.
1
u/DoListening2 May 22 '20
It is possible to do a gradual migration, where you would start with a compiler flag for your own code and libraries that also have it set (you can also safely use libraries that have
@NonNullannotations, etc.), with the rest being treated similarly to Kotlin's platform types - no strict checks, but use at your own risk.Eventually, most libraries would adopt this, or at least add the annotations. Way down the line, that compiler flag would be made the default.
I think Dart is currently undergoing a similar transition.
1
u/Yithar May 22 '20
https://www.reddit.com/r/java/comments/ee4h1x/null_safety/
However, seeing how Kotlin sometimes has uncanny long chains of "?." calls (e.g. Streams), I'm not convinced Kotlin has a completely superior solution. Especially since the
OptionalAPI is quite powerful in expressing missing values and arguably more readable than plain null checks.It seems though there are some frameworks that already read the
@NonNullannotation for null safety:Check NullAway and checker-framework (which can offer you a lot more)
And even more powerful than
OptionalisOption. I personally thinkOptionis really readable withmapandflatMapbut that's just my 2 cents.1
u/DoListening2 May 22 '20 edited May 22 '20
The problem with
Optionalis that you still have to deal with regularnullin the language. There is still a lot of code that returns/expects regular nulls. It may still seep in via uninitialized fields, etc. Without near-universal coverage, Optional's utility is greatly diminished, because you just can't rely on everything that is not Optional to also be non-null.I also don't see any problem with
?.. If the only argument is that it "looks ugly" to some people, that's completely subjective and a matter of habit. I personally don't seevalue.map(o -> o.field).orElse(defaultValue)as more readable thanvalue?.field ?: defaultValueat all. Plus you can use inline return syntax (val a = value?.field ?: return false, etc.).I mean, the dot operator is the way of doing field/method access, and
?.is just a natural extension of that. I would guess that the vast majority of code inside lambdas passed toOptional.mapis just plain field/method access and nothing else. Calculating other stuff in there surely must be much more rare (Kotlin's equivalent would be?.let { }, which is definitely used less often than?.fieldaccess). So turning plain dot-operator field/method access into a lambda insidemapdefinitely feels more clunky to me.1
u/BlueAdmir May 21 '20
Perhaps that's what they need to do - start a 10 year plan to retire and announce it left right and center.
0
May 21 '20
[deleted]
9
u/DoListening2 May 21 '20
There are 6-month release cycles now, and a roadmap of actual planned features.
0
May 21 '20
[deleted]
4
May 21 '20
How is kotlin a meme language? And how is modern java amazing? I can’t really think of anything modern java has that kotlin doesn’t.
0
May 21 '20
[deleted]
1
1
u/DoListening2 May 22 '20 edited May 22 '20
Non-nullable by default.
throw/return are expressions, so you can do
val email = user?.email ?: return nullLot more convenient stuff in the standard library.
1
u/slowpush May 22 '20
So just use Lombok if that is it important to you.
1
u/DoListening2 May 22 '20
But why would I? I gain nothing by avoiding Kotlin and sticking with Java. In fact, I'd still lose out on some of the nice-to-haves.
2
u/slowpush May 22 '20
Good luck debugging the generated nonsense Kotlin builds.
0
u/DoListening2 May 22 '20 edited May 22 '20
I don't understand what you mean. Debugging regular code works exactly like with Java - you can step through the code, see the values as usual, evaluate stuff, etc. I only very rarely care about reading the raw JVM bytecode if that's what you mean.
With asynchronous code and coroutines, there are some caveats (https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/debugging.md) for now, but you would have similar issues when using e.g. RxJava (very popular on Android) and wanting to step through a chain of operations. Or anything else where control flow basically turns into data flow.
2
u/moomoomoo309 May 21 '20
Your last statement is a bit weird. What does Java have that Kotlin doesn't that would make Java better?
2
u/Pika3323 May 21 '20
D8 desugars many new Java features anyway... there are many other aspects of Kotlin that have made it so popular, aside from being pushed.
0
May 21 '20
[deleted]
-1
u/Pika3323 May 21 '20
D8 desugars all of Java 8's language features and all Java library APIs up to at least Java 11. You can use all of those features in any Android app, and plus you can reference all those Java <=11 APIs in Kotlin too (
java.timeis a pretty notable one of you weren't already using a library).What more do you want? The
varkeyword? Switch expressions? Text blocks? Kotlin has all of those..0
May 22 '20
[deleted]
1
u/Pika3323 May 22 '20
Like I said, I'm not sure what Java 11, or hell even Java 14 features you think are missing that make modern Java so "great" in comparison.
Kotlin benefits from all of Java's new APIs and already has many if not all of the features being added from Java 8 through 19 (if you're to go with what's said in Jake Wharton's talk).
0
0
u/florinp May 21 '20
Really ? Has Java support for optional class attributes ? (one example)
1
u/slowpush May 21 '20
Great. Now implement that without breaking old code.
Playing a feature war isn’t what programming is about.
However a feature war is how meme languages get popular before dying off.
1
u/nutrecht May 22 '20
Playing a feature war isn’t what programming is about.
Calling Kotlin a 'meme language' is all fine but if someone points out Kotlin has some nice features Java can't implement then we suddenly "can't play feature wars". How convenient.
1
u/florinp May 22 '20
Please tell me how optional class attributes break old code.
p.s. don't downvote opinions you don't like.
0
u/ArmoredPancake May 21 '20
Modern java is absolutely amazing compared to kotlin.
Hahaha, no. Even doesn't have even half of Kotlin's features.
0
May 21 '20
[deleted]
2
u/slowpush May 21 '20
Not true at all. It’s easy to focus on old java because there’s so much of it out there.
94
u/BroodmotherLingerie May 21 '20
Time for some bean cake factory provider service factory.