Live data from Hacker News

Java is becoming more like Rust, and I am here for it

joshaustin.tech

41–50 of 71 posts

Re: Java is becoming more like Rust, and I am here for it

#41
post #32
post #3

The article is using immutable records and sum types as “more like Rust” and I am just sitting in the corner, wondering whether everyone has forgotten that these things came from FP in the first place. In my mind, a language isn’t “Rust-like” because it uses concepts we learned in FP. We have languages like Haskell and, before it, ML. And I know ML didn’t invent it. We also have Scala, and for Scala, we don’t even ha…

This was my knee-jerk too. It’s great to see some of the good bits of ML flow into new languages, but this isn’t some Rust-specific feature. As an annoying side-effect tho, it’s been harder to pitch FP in these existing spaces since now “we have FP at home” in the existing language (even if the ergonomics are worse, it looks uglier, the language idioms & existing programs don’t match the style, & ’the bad parts’ + fo…

Hey, incremental improvements are still improvements. Convincing everyone to change the world is hard just for immutable types or sum types or something. But I’ve seen that slowly adding in functional programming to Java caused my team to get aggressive about using it, and demand it in code reviews. Sometimes you just need the Trojan horse and people will like what they find. I don’t think I’ll convince my team to drop Java, but they’re convinced that FP is important to include, at least in little bits.

Re: Java is becoming more like Rust, and I am here for it

#42
I'm a big Rust person but the language I think that's slept on is Kotlin.

It has all the goodies I like in Rust (multiplatform, decorators, FP, pattern matching) but with a GC/JVM to back it.

I personally like Rust since I can drop down to low-level embedded projects and stick with one language, but depending on what interest you, Kotlin can be an excellent fit.

Re: Java is becoming more like Rust, and I am here for it

#44

I'm surprised there aren't more people using Java nowadays. The JVM is rock solid, the speed is really good, and the latest changes are making the language much more modern. Maybe people are actually using it but not talking about it? Not sure.

Generic erasure inside the JVM is a fundamental flaw.

There are some (imperfect) workarounds, ex: https://github.com/jhalterman/typetools

Re: Java is becoming more like Rust, and I am here for it

#45
post #9

Earlier quoted context omitted.

> Disclaimer: In no way am I claiming that these Rust features caused their counterparts to appear in Java > I would not be surprised if Kotlin and/or Scala were more influential in bringing this to life. But yeah, I agree, generally weak article. I don't think it shows that "Java is becoming more like Rust" at all, because of the two listed features.

A better way to say it is that Java is becoming more like Kotlin, which in turn was halfway between Java and Scala.

“Java is becoming more like Kotlin” lands you on the lower half of front page at best. “More like Rust”? Instant upvotes, #2 right now.

Re: Java is becoming more like Rust, and I am here for it

#46

I'm surprised there aren't more people using Java nowadays. The JVM is rock solid, the speed is really good, and the latest changes are making the language much more modern. Maybe people are actually using it but not talking about it? Not sure.

I have been playing with the zgc garbage collector and gc pauses are essentially a solved problem. On machines with 90+ gb of heap size gc pauses are taking 700 microseconds (us) at most.

Re: Java is becoming more like Rust, and I am here for it

#47

Earlier quoted context omitted.

I think async worked out pretty well with JavaScript. But that was added to an already async language, it was just verbose and awkward before the await keyword.

In what way was the language async? It has no threads outside workers, which have strict limits regarding data sharing. You would see a lot of code that registers callbacks as event handlers, but I don't think that makes the language async. That's just the nature of event handlers. They are invoked later, when the event happens. In a way, the lack of threading allowed `async` to be implemented without gotchas. In lan…

I think you have async mixed up with concurrency / parallelism. Async is all about events as opposed to blocking wait. As an example, Java had predominantly sync programming model, because the thread would be block-waiting for stuff, no matter the fact there can many such threads block-waiting.

Re: Java is becoming more like Rust, and I am here for it

#48

Isn't this more like "Java is becoming more like C#" ... again? Record types, immutable after construction: https://www.c-sharpcorner.com/article/c-sharp-9-0-introducti... Warning when a switch isn't exhaustive: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Record types in Java were added with Java 14, released March 2020, it was later that year, in November, that C# added them with C# 9.0.

I don't believe C# has anything like the exhaustive switch over a sealed interface that the article is talking about.

Re: Java is becoming more like Rust, and I am here for it

#49

What "immutable" means in Rust is very different from Java or any FP language for thar matter. In Rust you can take any data structure and mutate it. There are hardly any invariants that you can force, unlike in Java. For example, strings are mutable in Rust. This, coupled with not being a language managed by GC, makes persistent data structures not practical or desirable. Of course, mutability in Rust is very contro…

> In Java, culturally speaking, you don't see much immutability, but when you have immutability

This isn't strictly true. Almost all Java code I see day to day are immutable classes outside of those being used with JPA.

Re: Java is becoming more like Rust, and I am here for it

#50
post #35
post #3

The article is using immutable records and sum types as “more like Rust” and I am just sitting in the corner, wondering whether everyone has forgotten that these things came from FP in the first place. In my mind, a language isn’t “Rust-like” because it uses concepts we learned in FP. We have languages like Haskell and, before it, ML. And I know ML didn’t invent it. We also have Scala, and for Scala, we don’t even ha…

Everyone hasn't forgotten, they just aren't learning things from the bottom-up. It's Rust-like to the author because that's probably where he learned about it in the first place.

> It's Rust-like to the author because that's probably where he learned

I like about HN that everyone is so friendly about this type of thing. I personally don’t have a lot of patience for people who think new things are the greatest inventions and ‘the old is catching up’ (in this case Java catching up with Rust) while everything came from elsewhere originally. If you want to openly say these things, please research them first and attribute properly. But indeed it is good here we try to educate not shame or insult like some other communities.

Anyway: I would say people should learn bottom-up as we don’t need to invent the wheel every few years that way.

Post reply on HN