Fork me on GitHub
#off-topic
<
2024-03-03
>
Jorge Viana21:03:03

Does anyone know why Java doesn't have immutable persistent collections like Clojure or Scala. I know there are some libs but they seem to loose traction and end up not being maintained. So many improvements to Java and this is never thought of? Strange to me. Any thoughts? Thanks in advance

geraldodev22:03:52

Isn't Java Data Classes a java take on immutability ?

phill23:03:28

The Java language architect at Oracle keynoted Clojure/conj a few years ago. They're very well aware!

geraldodev00:03:11

Brian Göetz, Java concurrency in practice, has a section 3.4 on immutability. Clojure is his preferred JVM language https://www.youtube.com/watch?v=GedrGWu16_I

Martynas Maciulevičius06:03:25

1. Java's language strategy is to not force a gazillion LOC migration efforts (for instance as in javascript libraries or python 2 -> python 3). It would bring a lot of confusion if the old Collection API would be deprecated or be placed onto the brink of deprecation. So I think this is also avoided. 2. There are https://github.com/search?q=persistent+data+structures+language%3AJava&type=repositories&l=Java that implement persistent data structures and it actually doesn't need to be solved in the language (insert the famous foreach quote here where the compiler author has to intervene to support this syntax and individual developer is always faster to implement it themselves)

nikolavojicic08:03:34

java.util.collection APIs have a lot void methods all over it.

nikolavojicic08:03:41

There are unmodifiable implementations of those interfaces which throw if you call mutating methods, and there are streams. That covers a lot use cases. Adding additional methods (if possible, e.g. default) or new interfaces would just confuse users I think.

henrik09:03:37

There’s plenty of async frameworks, and they still decided to implement virtual threads. They could decide that a standardised set of immutable data structures would be valuable to have in core.

👍 2
nikolavojicic12:03:10

A lot of design decisions in project Loom is about the good integration of virtual threads with existing APIs.

nikolavojicic12:03:25

Ok, not with CompletableFuture, but many others.

emccue19:03:04

@U05C4RCR8BT There is a good deal of background discussion on it. If you watch some talks on the collections framework persistent collections is brought up as one of the few reasons they might consider a collections 2.0

emccue19:03:36

so its been thought of, just prioritized kinda low compared to other stuff and its uncertain whether they should be in the stdlib

emccue19:03:01

but there is the https://www.vavr.io/ library, which gives ~ the same API as the scala stdlib

emccue19:03:53

which as pattern matching, null restriction syntax, value types, etc. come out will probably deserve updates

emccue19:03:52

this is legitimately one of the upsides of java not having collection literals like [1 2 3] - the standard library isn't really privileged compared to external libraries