News for hackers. Stuff that matters.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by mike_hearn on Friday October 06, 2023 @12:18PM (#37792742)
The Clojure devs should be aware that the synchronization pinning problem is intended to be temporary and doesn't apply at all with GraalVM native images. One of the Loom developers talks about it here:

https://mail.openjdk.org/pipermail/loom-dev/2023-September/0...

So they could also just choose to ignore this problem for now.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by fnordsensei on Friday October 06, 2023 @12:31PM (#37792908)
A lot of Clojure projects choose to stick with the LTS releases though, so it might take a while before this problem disappears on its own, even if fixed in the JVM.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vemv on Friday October 06, 2023 @12:35PM (#37792964)
To be entirely fair, there's arguably little overlap between devs that stick to LTS, and devs that will play with JVM virtual threads on Clojure (before the Clojure team has any particular, public stance on them).
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by fulafel on Friday October 06, 2023 @01:18PM (#37793441)
Yes, especially since the use case for virtual threads is so niche.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by weatherlight on Friday October 06, 2023 @01:27PM (#37793537)
Is this sarcasm, or just generally true in the java community?
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by fulafel on Friday October 06, 2023 @01:53PM (#37793839)
Neither for me (I'm in the Clojure camp), it just seems to me there aren't many situations where you'd need millions of threads. Plus we've got core.async to reach for to multiplex many control flows on one OS thread - though I feel it's more needed when targeting JS (ClojureScript) and the single-threaded world there.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by weatherlight on Friday October 06, 2023 @02:14PM (#37794154)
I'm coming at this from a Erlang/Elixir background , Where we basically have "virtual threads" but they aren't at the OS level. It's easy to use and making things concurrent (or parallel) is often trivial. Whether it's 1 extra virtual thread or millions of virtual threads, the code (and the horizontal scaling of that code is the same)
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by raspasov on Saturday October 07, 2023 @02:14AM (#37799416)
I love core.async (been using it since... 2014 I think... both Clojure and ClojureScript), and yes, core.async/go basically was/is solving (some) of the same problems. But there's a number of gotchas around (go ...) blocks...

Without being an expert on the core.async internals, I believe core.async can potentially benefit tremendously from this, by the virtue of being a powerful and super-elegant API for communicating between different parts of an application (typically within the same JVM process). Now it can continue to do that, while (likely) being free from most macro gotchas...

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by bcrosby95 on Friday October 06, 2023 @01:57PM (#37793888)
I can't think of a project I've worked on in the past 10 or so years that couldn't benefit from virtual threads. Right-sizing your thread pools in an environment with a lot of IO is/was a pain in the ass.

Many of the core concurrency constructs in Clojure has separate functions for when you are doing something that is blocking vs not blocking. If it were all virtual threads this distinction generally wouldn't matter.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @02:06PM (#37794040)
Not just that - the kicker is everything that already exists (libraries, JDBC drivers, etc) are now just automagically non-blocking too if you seed the thread pool with a virtual thread factory.

I can't remember the last time such a transparent, drop-in-able change was so impactful for just about everything.

While it doesn't remove the need for the event/reactive/async paradigm in all cases, it does removes the need for async code just for the sake of being non-blocking.

Code can now be written much more clearly, and still be non-blocking. That's huge.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by raspasov on Saturday October 07, 2023 @02:08AM (#37799388)
It's niche if you don't have much traffic/request volume/etc.

Once you have even an arguably relatively small amount (100s to 1000s of requests per second) it can be a game changer in terms of efficiency.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by fulafel on Saturday October 07, 2023 @04:19AM (#37799991)
Are there published case studies or other empirical evidence available with numbers about this?

OS threads in Linux are fast and you can have a lot of them. Eg https://news.ycombinator.com/item?id=37621887

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by raspasov on Saturday October 07, 2023 @04:53AM (#37800155)
Just try starting ~100,000 threads that each sleeps for ~60 seconds in your JVM and check if you can succeed! :)

``` (run! (fn [x] (future (Thread/sleep 60000))) (range 100000)) ```

(hint: likely not...)

TLDR; Efficiency difference: you can think of virtual threads as being about 1,000 times (3 orders of magnitude) less expensive, in the general case. Exception: If you are only doing CPU-only work, regular threads will be better (that's not how most web servers/services operate).

But if you're waiting 100ms of ms for your database (or any network) to respond and you have many of those (blocking) method/function calls in flight... virtual threads are the way to go in terms of efficiency.

Great video explaining all of this (at timestamp, all 30 min is worth watching):

17:05 Making threads less expensive: by how much? https://www.youtube.com/watch?v=5E0LU85EnTI&t=1025s

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by fulafel on Saturday October 07, 2023 @09:30AM (#37801560)
On a wimpy old desktop running lots of other stuff I got 75000 threads (had to increase max_map_count first, which is well documented for bigger thread amounts). Considering that in a real world use case with that much concurrency (such as your "threads frequently waiting for db" scenario), I'd be using a bigger machine and there'd also be some actual application context data and TCP connection state dwarfing the thread memory requirements in those blocked contexts, I'll still call virtual threads solving quite rare use cases, pending stronger evidence.

I don't doubt virtual threads are efficient when microbenchmarked against OS threads, but there's only so much to be gained when optimizing a part of the system that wasn't a bottleneck to begin with.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by raspasov on Sunday October 08, 2023 @12:06AM (#37807793)
Right... but using virtual threads I got 1,000,000 (in a second or two...) and likely for fraction of the memory. And I can even get many millions without a problem.

I agree that for a low volume typical CRUD-only server that never bursts above a few dozen requests per second that's not an issue.

Messaging is one special "rare" case.

Imagine a messaging channel in Slack/Discord/Telegram/WhatsApp-type app, where there's thousands of participants (say 10,000) in one channel. 1 person posts a message...

9,999 messages are generated (one to for each of the other participants). One might say, that can be handled with a few machines...

Now imagine a person posts something super interesting to the channel where 100 people respond with an emoji reaction almost instantly.

Now you have 100 * 9999 = 999,900 (!) messages, all within a few seconds! And this is for just one message _reaction_. Each one of those messages likely involves multiple steps of IO (sending/receiving data over the socket, writing to one or multiple databases...). So a thread might be blocked for hundreds of milliseconds at various times, which would ultimately likely require 100-1000x more servers to operate as scale increases.

The thing is that you _can_ write a program efficiently using regular threads by using asynchronous techniques. Another name for such style of programming is _callback hell_ :) . And when something does go wrong, it is a lot harder to debug.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Friday October 06, 2023 @12:46PM (#37793075)
As pron always says.. that's a risk of staying on an LTS release. You're choosing to not receive updates.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by geodel on Friday October 06, 2023 @01:20PM (#37793473)
It seems to me by design or by indifference Java is now tired of JVM ecosystem languages at large who claim innovation by surface level changes while relying heavily on JVM bedrock.

Now Java is moving fast and they are taking JVM compiler, runtime, class metadata etc along where Java, the language is headed.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @01:46PM (#37793758)
Not only Java, that is the fate of all guest languages, as they don't evolve alongside the platform, always require additional tooling and most language cultures than start making their own little islands of idiomatic libraries instead of directly using platform libraries.

Since most platforms are leaky, one ends up needing to master two ecosystem in parallel, eventually it gets tiring and always cost extra in development.

C++, Objective-C and Typescript get around this problem in UNIX and Web, as they are extensions of the platform languages, not something completely different.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by geodel on Friday October 06, 2023 @02:07PM (#37794063)
Yep agree with all you said. Nowadays new job every year people at work are scaring me with their enthusiasm to replace decades old solid Java applications which are performant and working fine with Kotlin and what not.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @02:12PM (#37794127)
I wouldn't advocate for replacing/re-writing old stuff - but you should try out Kotlin for backend work. It's amazing.

Java programmers will have only a small learning curve before feeling productive, and can gradually get more comfortable with idomatic Kotlin as they progress through their journey.

Kotlin, as a language, was very well through out, letting you use as much or as little of it as you are comfortable with.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by jcadam on Friday October 06, 2023 @02:38PM (#37794498)
Kotlin is the closest thing to a "better Java" that I've found. I've used it with Spring Boot and the interoperability with Java is fantastic. A Java dev would have no problem picking it up quickly (as opposed to Clojure and even Scala).

I say this as a Clojure fan, there are many instances where I'd probably choose Kotlin nowadays. You can also mix JVM languages within the same application; I've found it rather useful to sprinkle some Clojure into a Java/Spring application for certain tasks. Maven and Gradle both have tooling to handle it :)

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @02:48PM (#37794626)
If you're into FP stuff, using Arrow within Kotlin takes you to that next level. It even works with Spring/Boot.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by ahoka on Friday October 06, 2023 @03:35PM (#37795205)
Even C# seems like something stuck in the 1990s compared to Kotlin. (I know it’s not a high bar).
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @03:38PM (#37795248)
Not kept up with the times in regards to C# 12 features?
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @06:45PM (#37797304)
C#'s problem is it's quickly becoming C++ in that it doesn't just have the kitchen sink, it has three kitchen sinks...

Unlike C++ though, one day the powers that be will just remove features as part of yet-another framework rewrite and you'll just have to deal with it.

The other issue is just how tightly coupled C# as a language is to the .NET framework/platform. Some of the things people like C# for are actually framework things and they don't realize it because that separation isn't as clear as with Java and say, JavaEE or Spring or $X.

If you talk to a C# developer - of course they're using .NET and of course they're using Entity Framework - to them, there's no other way. It's inconceivable that any other library or framework might do it better than Microsoft's official offering... and then you'll find the official offering to be lacking in fundamental ways.

Talk with a Java developer and you'll find there's a lot more diversity of frameworks and libraries being used - so there's a lot more differing opinions on priorities and a lot more good ideas being tried out or implemented everywhere. The communities are vastly different in that regard.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Rapzid on Saturday October 07, 2023 @12:45AM (#37799076)
Collection literals are going to be fantastic. Many don't know that there is actually momentum to keep moving right into Dictionary literals.

There is a "roles" proposal and investigation team. This roles proposal is going to unlock so much potential it is bonkers.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by melolife on Saturday October 07, 2023 @09:12AM (#37801432)
Collection literals are a pointless extension of the pattern matching syntax added to get around the fact that there is no way to name a generic type in C# without specifying its type arguments.

It's yet another double down on object initializers instead of writing constructors and factories, and unlike using a factory you have to fully express the result type of the collection instead of having it inferred (they are "target typed", another feature that probably should not have been added).

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Rapzid on Saturday October 07, 2023 @04:14PM (#37805137)
There is a pattern matching aspect but I think the energy behind it is largely motivated by a desire to clean up syntax when working with data structure based APIs and DSLs.

I've read the proposal, design meeting notes, and GH conversations. Not seeing a compelling counter argument here.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by ahoka on Saturday October 07, 2023 @02:28AM (#37799480)
What do you think I’m missing that makes C# 12 not a-lot-of-lipstick-on-a-java-pig?
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by bafe on Friday October 06, 2023 @03:52PM (#37795426)
Couldn't agree more! It's particularly disappointing when you need to work on an older java codebase after finishing a Kotlin project. You'll constantly miss features
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Saturday October 07, 2023 @08:32AM (#37801181)
> You'll constantly miss features

Like what?

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by bafe on Saturday October 07, 2023 @11:38AM (#37802617)
Nullable types, module level functions, context receivers, nicer type signatures for functions, a better standard library (e.g map works directly on lists without the stream.map crap)
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Saturday October 07, 2023 @09:40PM (#37807103)
Personally, these features are not something I feel like I would constantly be missing. I don't constantly feel like I'm missing them after switching from JavaScript, at least for not having to call .stream(), context receivers (which Java provides with ScopedValue), or signatures for functions.

I'll give you nullable types, though I personally don't struggle with null at all.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @02:23PM (#37794279)
It is still another syntax, with idioms moving away from JVM, their own little islands of Kontlin only libraries, and only works on InteliJ/Android Studio.

I don't see any value in Kotlin outside Android shops.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by jcadam on Friday October 06, 2023 @02:45PM (#37794585)
> I don't see any value in Kotlin outside Android shops.

Developer experience is important to some people - not just devs, but those who seek to recruit and retain good ones.

Of course, if you're looking to hire massive numbers of butts-in-seats (gov work, large enterprise shops, etc) I suppose Java is probably the ideal choice.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @02:46PM (#37794591)
While true it has it's own syntax, the syntax is better than Java and more ergonomic. With that said, you can write Java in Kotlin - and by that I mean Kotlin code that looks almost exactly like Java. Heck, you can have .java and .kt source within the same project all mixed together if you want.

Kotlin libraries are interoperable with Java and vice versa. In some specific cases, a Kotlin library needs a little syntactic sugar to make it work with Java like a Java developer would expect, but it's easy to do. Going the other direction though - Java library used in Kotlin, zero issues, it just works. Some Java developers don't even realize they're already using Kotlin - take a look at OKHttp and friends...

Lastly, there's Kotlin support is all major IDE's, including IntelliJ of course, but also Eclipse and likely whatever editor/ide you prefer. Kotlin is basically just a bunch of libs.

I would argue Kotlin is better outside of Android than in Android. For backend work, particularly when coupled with Spring/Boot, it's freaking amazing. The Spring team has put in an impressive amount of work to make Kotlin a first-class language within the ecosystem, and it really shows.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @03:36PM (#37795216)
Try to call Kotlin co-routines from Java.

Telling me there is Kotlin support in Eclipse only tells me you never actually tried it, specially after JetBrains ramped down the team that was doing the now stale plugin.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @03:39PM (#37795256)
You should look harder before saying it doesn't work. Updated 10/6/2023[1]

Coroutines are a specific paradigm within Kotlin, and should not be in library code anyway. With the addition of JVM Virtual Threads, the need for Coroutines is significantly diminished anyway.

It's anecdata, yes, but I've written a lot of Kotlin code and do not use coroutines. Kotlin really just lets you do what you want - as much or as little idomatic code as you need.

Kotlin on the backend is amazing. You really should give it a try. Java sucks badly, in comparison (I say that as a former Java nerd...)

[1] https://marketplace.eclipse.org/content/kotlin-plugin-eclips...

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @03:42PM (#37795301)
And you should read before posting random links,

   After installation of the Kotlin plugin the Java plugin is not running anymore. I cannot open a Java project anymore.

   The log file says:

   !MESSAGE org/eclipse/jdt/internal/ui/refactoring/actions/RenameJavaElementAction$AjcClosure1
   !STACK 0
   java.lang.NoClassDefFoundError: org/eclipse/jdt/internal/ui/refactoring/actions/RenameJavaElementAction$AjcClosure1
    at org.eclipse.jdt.ui.actions.RenameAction.<init>(RenameAction.java:60)
    at org.eclipse.jdt.ui.actions.RefactorActionGroup.<init>(RefactorActionGroup.java:372)
    at org.eclipse.jdt.ui.actions.RefactorActionGroup.<init>(RefactorActionGroup.java:206)
    at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.<init>(PackageExplorerActionGroup.java:139)
    at ...
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @03:45PM (#37795322)
You copy/pasted an error some random person on the internet had in June due to using an incompatible Eclipse & plugin versions?

The beauty of Eclipse is the ecosystem. If that official Jetbrains plugin doesn't do it for you for some reason, then use another one[1].

[1] https://marketplace.eclipse.org/content/enhanced-kotlin-ecli...

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Tainnor on Friday October 06, 2023 @03:00PM (#37794782)
"Only works on IntelliJ" is patently false. Stop spreading FUD.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @03:34PM (#37795187)
Where is Kotlin support for Eclipse and Netbeans?

Prove me wrong.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @03:38PM (#37795241)
Do you use Eclipse? Have you looked at the available plugins?

There's nothing special about Kotlin. It's a bunch of libraries for runtime and compile time... like anything else you use.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @03:40PM (#37795276)
It is my main Java IDE.

There is a difference between supporting a language with a Notepad++ like experience, and what JetBrains was doing before ramping down the Eclipse plugin team, as means to sell more InteliJ licenses instead.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @03:42PM (#37795302)
What do you believe you are missing?

It compiles fine with Maven or Gradle, it provides auto-prompt/complete/hints. It just works.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pjmlp on Friday October 06, 2023 @03:44PM (#37795317)
Same experience as in InteliJ, which JetBrains no longer provides.

And above all, no crashes left and right.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @03:46PM (#37795342)
I'll ask again more clearly - what is the "same experience" you are missing?

Kotlin is plugins for Maven/Gradle, and classpath libraries. There is no magic going on here...

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by pianoben on Friday October 06, 2023 @06:29PM (#37797179)
I've worked in several JVM backend projects, and Kotlin has been a stark improvement over Java (at least up through version 17, the most recent with which I've worked directly). Compose, and Compose UI, are tremendously promising technologies; I've shipped desktop apps with Kotlin for multiple platforms, and compared to just about every other desktop UI framework, it's a clear winner in terms of productivity and an ability to GSD.

All that to say, I believe that Kotlin has a lot of value, independently of Android.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Friday October 06, 2023 @03:18PM (#37795007)
For me personally Kotlin does not bring that much to the table over a modern version of Java. Sure if you're stuck in Java 8 it can be a win, but compared to Java 21 it just doesn't bring enough to warrant the switch for me.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by skwirl on Friday October 06, 2023 @03:57PM (#37795496)
I’ve seen this sentiment a lot and I don’t understand it. I actually feel like very little has been added between Java 8 and Java 21. Virtual threads is probably the biggest thing, and it looks very promising, but the language itself is still a chore to use, and Kotlin does a good job at cleaning a lot of that up.

I think Kotlin is at risk, though, of having the JVM force them to support two competing models to accomplish the same thing - coroutines and virtual threads is a good example (although Java still doesn’t have language level structured concurrency). This could really make things messy.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Friday October 06, 2023 @04:06PM (#37795618)
> I’ve seen this sentiment a lot and I don’t understand it.

I just don't think any feature of the language of Kotlin is that much better than Java's implementation. I'm also a big supporter of brevity != clarity when it comes to code.

What language feature in Kotlin do you think is that much better?

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @05:19PM (#37796557)
I was you not that long ago. I've had the same conversation with a lot of other Java developers too - they/we always say the same things.

It's weird being on the other side of the fence now - hearing the same things I used to say.

Kotlin was a gateway drug out of not just Java, but OO/Solid and into FP for me (FP being another thing I used to not "get"). The beauty of Kotlin is you don't have to ever write FP code if you don't want to - but you will want to before too long.

I would recommend trying it out for yourself. It's Spring integration is amazing, and you'll have a great time. Write even a little Kotlin and you'll have an "ah ha!" moment and everything will forever be different.

It's one of those things where you need to experience it for yourself before you actually understand how great it is. There is no argument you will hear that will convince you, sadly. I was the same once...

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by bcrosby95 on Friday October 06, 2023 @07:25PM (#37797603)
To me Kotlin is different enough to be annoying to learn, but not different enough to matter that I use it over Java. So it just kinda feels like a waste of time.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by kaba0 on Saturday October 07, 2023 @03:04AM (#37799648)
You can do many FP things in Java as well, as it is a multi-paradigm language, hell, Kotlin is not even particularly functional-y.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Tainnor on Saturday October 07, 2023 @07:38AM (#37800861)
I'll agree that Kotlin is not hardcore FP (although you can get there some of the way with Arrow etc.), but FP in Java is clunky.

- Having to remember the difference between "Function", "Consumer", "Predicate" and "Supplier" is weird. In Kotlin (and basically every other typed FP language that I know), I just write the type signature the natural way.

- Having to use streams in order to use map, etc., is noisy. Why weren't these APIs retrofitted to collections?

- Checked exceptions are a pain with functional code, e.g. map.

- Mutability is still the default behaviour of almost everything in Java, save records (and strings).

etc.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by sitta on Saturday October 07, 2023 @08:08AM (#37801027)
> Having to use streams in order to use map, etc., is noisy. Why weren't these APIs retrofitted to collections?

Sure, methods along the lines of the following could have been added:

  public <R> List<R> map(Function<? super E, ? extends R> mapper) {
      return stream().map(mapper).toList();
  }
Yes, having them would make Java less verbose in the case where you only want to do a single map, filter, whatever operation on a collection, but I'm personally glad that they weren't because they produce extremely inefficient behavior when chained. So, it would add a performance footgun to save ~18 characters.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Saturday October 07, 2023 @08:30AM (#37801167)
But are these things enough to warrant me a full switch of programming language and ecosystem? Not for me.

- I don’t think this is really that big of a deal.

- Using streams is actually preferred so you don’t cause a performance nightmare and kotlin you has to use asSequence anyway.

- I thought checked error handling was all the rage nowadays?

- Mutability is absolutely fine if you’re not going over a thread boundary.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Tainnor on Saturday October 07, 2023 @04:44PM (#37805394)
In Kotlin, asSequence gives you lazy behaviour (i.e. chains of map, filter, etc. are merged the way it's automatically done in Haskell), but if you don't care about the performance penalty, you can just call map, filter etc. on eager collections too. I'm of the opinion that you shouldn't prematurely optimise, for small enough data, it often doesn't matter much.

And checked exceptions are widely seen as an anti-feature - I don't think any other language has them, with the possible exception of Swift (see below), and for good reason. Other languages encode errors (more or less ergonomically) in the type system (e.g. Rust, Haskell, and to an extent it's what Kotlin advocates as well), and that has the advantage of playing well together with other language mechanisms - e.g. no extra allowances need to be made so that map works with them.

But for the sake of the argument: Swift also has something similar to checked exceptions, but only in the sense that functions can either throw or not throw. However, Swift also at least has constructs like "rethrows", which lets you say that a function such as map should throw iff the higher order function it wraps throws.

Java simply decided that it doesn't need to deal with this problem at all (for whatever reason - they simply could have added something like "rethrows") and now it's up to callers to deal with the incredible awkwardness that is using FP with Java library code that makes heavy use of checked exceptions.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by haspok on Saturday October 07, 2023 @10:26AM (#37801962)
Null safety checks and if being an expression are major pain point resolvers that are still not available in Java (OK, maybe pattern matching helps the if-expression part, because pattern matching IS an expression in Java). Oh, and the legacy library APIs, which Kotlin elegantly wraps with FP-compatible classes. Instead of fiddling with streams (which also lack some basic operations, or have some not so nice API), you can just .map or .fold over your (read-only by default) collection. Not only less verbose, but also easier to use and understand. Having said this, these are fairly minor things, which may not warrant a switch to Kotlin, if you are otherwise happy with Java...
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by sitta on Friday October 06, 2023 @05:31PM (#37796696)
> I actually feel like very little has been added between Java 8 and Java 21.

var, records, sealed types, and pattern matching make a huge difference in how Java is written. A lot has changed since 8.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Alupis on Friday October 06, 2023 @06:43PM (#37797284)
The issue with these new structures is they're necessarily clunky, to maintain interoperability with non-modern Java. Java's backwards compatibility is legendary, but is also why some of it's newer features are often criticized as not being as good as they could be.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by sitta on Friday October 06, 2023 @07:16PM (#37797539)
It's one thing to say, "very little has been added between Java 8 and Java 21," and something else entirely to say, "newer features are often criticized as not being as good as they could be [to maintain backwards compatibility]."
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by kaba0 on Saturday October 07, 2023 @03:06AM (#37799658)
I don’t think any of then is clunky - hell, pattern matching is straight better in java.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by skwirl on Saturday October 07, 2023 @02:56PM (#37804472)
This is a pretty unimpressive list for 9 years of progress, and is merely a small subset of features Kotlin was already providing.

I left the Java world for the C# world around 2008 and then returned to the Java world last year. C#/.NET changed much more significantly much faster. Almost all of the significant differences in day to day life with respect to the Java language and standard libraries that occurred between 2008 and 2022 are due to changes introduced with Java 8.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by koreth1 on Friday October 06, 2023 @07:48PM (#37797763)
> I think Kotlin is at risk, though, of having the JVM force them to support two competing models to accomplish the same thing - coroutines and virtual threads is a good example

I don't think it's that good an example, though there's some merit to it. Kotlin coroutines, to me, target three main use cases:

1. An abstraction over an underlying threading model. Get threaded execution without having to explicitly deal with thread pools and such. I'd consider structured concurrency to be part of this use case.

2. A way to write non-blocking code that is structured as if it were blocking. (Incidentally: I love Kotlin's decision to make "await" opt-out instead of opt-in.)

3. A way to write code that generates sequences of values without having to either write an explicit class that maintains state across calls or use callbacks/CPS. Or in other words, a way to use the "yield" function.

Use case 1 still makes sense with virtual threads. Run your coroutines on an executor that uses a virtual thread pool instead of a platform thread pool. If you prefer the coroutines API, you can still use it for structured concurrency and such.

Use case 2 is much less interesting in the presence of virtual threads; you can just write blocking code directly, no need for the language to turn it into async code for you.

Use case 3 has nothing to do with threads to begin with, so it remains exactly as valuable as before and there's no reason to change any existing code at all.

Do coroutines get less useful in the presence of virtual threads? Absolutely. But they aren't competing with virtual threads; there are substantial non-overlapping use cases that make them a worthwhile language feature.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by AgentME on Friday October 06, 2023 @07:21PM (#37797571)
Honestly the main thing I find killer about Kotlin over Java is its stricter null safety (types do not permit null values unless you mark the type as nullable with a "?" suffix). (I know Java does have the @Nonnull annotation but it's extremely verbose to use much and Java doesn't enforce its use on values that are expected to be non-null, which both greatly diminish its usefulness.) I've been spoiled by languages like Typescript and Rust which have great null safety like Kotlin, and it's very annoying going back to a language without it and questioning whether a null is expected or possible for every single value.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by unlikelytomato on Friday October 06, 2023 @10:44PM (#37798584)
I wish I could get a strong sense of the hype around null safety. Sure, I would like to have the extra expressive option. However, optional has been fine for me. I still barely use it. It has to be at least 3-4 years since I last encountered a null pointer exception in my daily java programming. I feel like there are plenty of other things that pain me on a daily basis that rank far higher on my asks for the language. Collection and stream ergonomics cause constant pain, for example.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by usrusr on Saturday October 07, 2023 @03:39AM (#37799817)
Infinitely chainable expressions, .let, .also and friends. You shouldn't overdo it (lengthwise) and it's almost hilariously superficial, but I miss it in every other language since.

Tying down a value to a name only if you have something meaningful to say in the name, and only when the value is actually finished instead of being a work in progress, that gives me great piece of mind and frees up mental resources for other things. I wish every language had a "kotlinized" sibling that simply added the scope functions on syntax level (or a subset of the scope functions, not sure you need a zoo that size)

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Saturday October 07, 2023 @08:23AM (#37801115)
I personally find let, also, and friends to be a clarity nightmare. For me, they make reading code harder.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by usrusr on Saturday October 07, 2023 @10:14AM (#37801872)
It's not always better, I give you that. If something does not work as expected you might even find me transforming code to conventional imperative style. But I feel like I have a much better shot at getting it right in the expression chain style, and in all styles if scopes are not polluted by dubious intermediaries and/or badly named one-callsite functions thanks to letisms. By the time the "let tax" grows too high, chances are that the block in question is big enough to make the "factored into a function tax" bearable.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by peterashford on Saturday October 07, 2023 @04:27AM (#37800021)
I did a year of Kotlin in a recent job. I liked it, but not enough to prefer it over Java - especially with the recent updates to Java. YMMV
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by never_inline on Friday October 06, 2023 @02:10PM (#37794104)
That's an interesting hypothesis. Is that applicable to platforms other than programming languages?
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by imtringued on Sunday October 08, 2023 @05:52AM (#37809162)
That would only be a bad thing if the Java ecosystem was good to begin with.

From my perspective it is terrible enough that the language specific wrapper library has 10x to 100x the usability of the Java option if you use it directly from Java. For example, GORM for Groovy is significantly better than Hibernate even though it is built on top of Hibernate. It is so good that I chose to use groovy once, not because it made sense but simply because Hibernate is so terrible, the cost of a different language was outweighed by it.

I don't give a damn about most JVM features. They don't change the crap ecosystem at all. I personally despise the JVM for being incredibly memory inefficient as well. None of this is going to change.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Tainnor on Friday October 06, 2023 @02:56PM (#37794733)
And many developers are tired of Java making minuscule improvements to developer ergonomics while pretending to be progressing, when even now, it doesn't have features that other languages have had for 30 years.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by kaba0 on Friday October 06, 2023 @03:17PM (#37794985)
Based on pure statists about the number of important, business critical java-applications that run most of the internet, it seems like it just straight doesn’t matter in any significant way.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Tainnor on Friday October 06, 2023 @03:20PM (#37795032)
Maybe it doesn't matter to you, but it does matter to me.

All the power to people who enjoy working in Java, but that doesn't have to make me like it.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by vips7L on Saturday October 07, 2023 @08:44AM (#37801260)
The JVM and Java the language have always been intertwined. The same people that develop the language, develop the VM. Lots of optimizations in the VM know specifically about Java the language idioms and implementation details. Check out this function which helps determine if instance fields are trusted: https://github.com/openjdk/jdk/blob/edd454b502b9bacde5549282...
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by koito17 on Friday October 06, 2023 @01:03PM (#37793270)
In fact, the officially supported Java releases for Clojure are all LTS releases. This is also reflected in their CI. At the moment, that means 1.8, 11, 17, and 21.

I would also like to mention, for non-Clojure users: it took ages for Clojure to finally get off Java 1.5. The compiler was still emitting 1.5 compatible bytecode as late as 2018. Since the release of Clojure 1.10 (17 December 2018), the minimum Java version was bumped up to 1.8, in the sense that the compiler now emits 1.8-compatible bytecode.

There is a strong emphasis on moving slowly and NOT breaking things in the Clojure community. Likewise, if you look at the most recent Clojure survey results, the vast majority of people were still on 1.8 and 11 releases.[1]

[1] See Q24 in https://www.surveymonkey.com/stories/SM-_2BH3b49f_2FXEkUlrb_...

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by tombert on Friday October 06, 2023 @01:52PM (#37793826)
I actually do feel like this is partly what's responsible for Clojure's relative success in industry. If you have a company with a ton of Java 5 code, and you want some of the sexy functional programming features, your options basically boil down to "upgrade everything to the newer Java 8 to get maps and optionals and whatnot" or "just write this new service in Clojure that will happily interop with our Java 5 code".

I'm not making a judgement on which decision is better, but I can totally see the appeal, at least in the short term, for people choosing Clojure, especially if they think that Clojure's API will be largely unchanged in the Java 8 update. It doesn't hurt that Clojure is just broadly a really pleasant to work with, at least in my opinion.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Quekid5 on Friday October 06, 2023 @06:26PM (#37797153)
> If you have a company with a ton of Java 5 code...

You are in deep deep trouble already, just process-wise. If you're making money hand over fist you might be able to afford to do that, but choice of language is not even on the radar in terms of what needs fixing.

Now, if you mean in terms of digging out of that hole... just upgrade to newer dependencies, newer JDK versions, etc. That's the way to better performance, better memory usage, better GC, better everything... and THEN think about the language you're using.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by nlitened on Saturday October 07, 2023 @02:00AM (#37799355)
> You are in deep deep trouble already, just process-wise.

Code is usually a much smaller piece of company's business process than we developers like to think.

> If you're making money hand over fist you might be able to afford to do that

Here's the problem though: the vast majority of companies on the planet don't "make money hand over fist", they just have small to reasonable profit margins. And most businesses can't just risk losing what's already been working for a decade just because some developers want a new shiny thing every six months.

That's the reality which JVM and Clojure folks take very seriously, but is very often overlooked by younger people.

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by chasd00 on Saturday October 07, 2023 @07:58AM (#37800966)
These are very good points. The programming language used is a tiny sliver of the pie chart required to run a profitable company. The entire “technology” portion of that pie chart is still only around 20% (at best) of a profitable company.
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by Quekid5 on Saturday October 07, 2023 @06:38PM (#37806129)
> Code is usually a much smaller piece of company's business process than we developers like to think.

I agree.

Btw, I think you inverted the meaning of my sentence regarding 'hand over fist'. I was saying that staying on an old version is asking for trouble and is going to cost a lot more than upgrading.

> That's the reality which JVM and Clojure folks take very seriously, but is very often overlooked by younger people.

Ah, the irony of being called young because of a comment I made :). I'm an old hand at this point.

FWIW, my shop also stayed on JDK 8 for a bit longer than we should have, but that was largely because of upstream dependencies. We're currently on JDK11, but again just because there are some upstream dependencies that are holding us back from JDK17. (It's mostly to do with the infamous module system change. It's a good change overall, but some projects have been super-slow to adapt.)

Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by kamma4434 on Saturday October 07, 2023 @07:07AM (#37800721)
You can definitely run a lot of 1.5 code on 1.8 and never notice
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by puredanger on Friday October 06, 2023 @02:31PM (#37794415)
We are aware, and that is one of the options. :)
Re:Java 21 VirtualThreads vs. Clojure Lazy Seqs (from Clojur... by puredanger on Friday October 06, 2023 @02:33PM (#37794431)
The other thing I didn't mention is that the change to remove biased locking a while back has also had an impact in some places that do almost always uncontended locking, so we're kind of considering that too.