News for hackers. Stuff that matters.
Re:Algebraic Data Types for C99 by lupire on Thursday May 09, 2024 @09:25AM (#40307980)
Kotlin is JVM compatible and has ADTs.

Java has https://github.com/functionaljava/functionaljava

which is unsupported but stable.

Re:Algebraic Data Types for C99 by tombert on Thursday May 09, 2024 @09:34AM (#40308077)
Sure, and Scala has had ADTs since its inception as well I think, and that's also JVM. It's not ADTs, but Clojure does have some level of pattern matching/destructuring as well.

It wasn't that I though that the JVM was incapable of doing something like an ADT, just that vanilla Java didn't support it. While it's easy to say that "companies should just use Kotlin", that's a bit of a big ordeal if you already have a 15 year old codebase that's written in Java.

I've heard of but never used the Functional Java library, though it'd be a tough sell to get my work to let me import a library that hasn't been updated in two years.

Re:Algebraic Data Types for C99 by Tainnor on Thursday May 09, 2024 @02:26PM (#40311297)
> that's a bit of a big ordeal if you already have a 15 year old codebase that's written in Java.

JetBrains has prioritised compatibility with Java and it shows. Of course, there are some gotchas (such as nullability or checked exceptions which don't exist in Kotlin), but you can really mix Kotlin and Java code relatively freely.

Re:Algebraic Data Types for C99 by brabel on Thursday May 09, 2024 @01:32PM (#40310620)
Java 21's pattern matching (you don't need functionaljava, and shouldn't really use that unless you're really into FP) is kind of nicer than Kotlin's, because you can automatically "destruct" records in your matches.

For Java, see https://www.baeldung.com/java-lts-21-new-features

Kotlin's: https://www.baeldung.com/kotlin/when

Make up your own mind.

Re:Algebraic Data Types for C99 by ackfoobar on Friday May 10, 2024 @01:00AM (#40315618)
> kind of nicer than Kotlin's, because you can automatically "destruct" records in your matches.

I find positional destructuring of records a bad idea.

https://news.ycombinator.com/item?id=31399737