News for hackers. Stuff that matters.
Re:Java 16 by benjiweber on Tuesday March 16, 2021 @11:14AM (#26477824)
Lots of shiny new toys to play with :) I like playing with new features and pushing to silly limits. Here's some fun things you can do now:

Compiletime checked state machines with Sealed Classes [preview feature] https://benjiweber.co.uk/blog/2020/10/03/sealed-java-state-m...

Autobuilders, Mixins, Conversions & more with Records https://benjiweber.co.uk/blog/2020/09/19/fun-with-java-recor...

Pattern Matching fun https://benjiweber.co.uk/blog/2021/03/14/java-16-pattern-mat...

Re:Java 16 by bob1029 on Tuesday March 16, 2021 @12:05PM (#26478636)
If you enjoy pattern matching in Java, I would recommend checking out the latest & greatest that C# has to offer as a comparison:

https://docs.microsoft.com/en-us/dotnet/csharp/pattern-match...

Being able to combine pattern matching with switch expressions has allowed us to construct extraordinarily concise state machines for our UIs.

Re:Java 16 by victor106 on Tuesday March 16, 2021 @12:34PM (#26479080)
I used Java a lot and like some aspects. But I think C# is way ahead in some important ways and Java is playing catch-up
Re:Java 16 by kaba0 on Tuesday March 16, 2021 @04:04PM (#26482105)
Java is really conservative language-wise while C# is pretty much add everything you see, reminiscent of C++.

Also, a significant part of Java development happens at the runtime level, where I would wager the catch-up is in the opposite direction, in some areas by quite large margins.

Re:Java 16 by Aa9C4xPz43Gg7k6 on Wednesday March 17, 2021 @04:29AM (#26487950)
C++ had shoddy foundation where adding more stuff is far from trivial.
Re:Java 16 by cmckn on Tuesday March 16, 2021 @02:48PM (#26481135)
Not considering async/await (because I'm not really a fan), they're neck-and-neck in my opinion. I don't think C# has been as careful with its abstractions and the general aesthetic of the language to the degree that Java has; but in many cases you can almost compile a block of Java as C# and vice versa. I think the primary differentiator is what toolchain/ecosystem you prefer, and I'm solidly on the Java side of that line.

That being said, I'm currently getting paid to write C#, so if you've got any resources for converts, I'd love them! :)

Re:Java 16 by jayd16 on Tuesday March 16, 2021 @09:58PM (#26485626)
What do you think is more elegant in Java than C#? I like both but I think things like LINQ, delegates, reflection, nullabity and even properties are much cleaner in C# vs streams (exceptions?), consumer<T> (weird names. accept? not invoke?), erasure and then just in general its not as nice, Optional<T> (its nullable?!), and getters/setters (I don't want to code gen this away).
Re:Java 16 by lstamour on Wednesday March 17, 2021 @01:36AM (#26486985)
> What do you think is more elegant in Java than C#?

Broad availability of third-party libraries? Java Flight Recorder? IntelliJ? Multiple build system options including first-class support for Bazel, Gradle, and so on. (Msbuild gets old quick...)

That said, personally I prefer TypeScript over all of the above if performance isn't an issue. ;-)

Re:Java 16 by jayd16 on Wednesday March 17, 2021 @04:37AM (#26488010)
We're talking about language design choices not ecosystem.

Even still, libraries are not a problem. Nothing you can't do in C#. You should check out Rider. Bazel and Gradle are cross platform as well.

Flight Recorder is good. I'll give you that. The .NET debugging tools are top notch...on windows. JFR wins out handily until the Linux tools reach parity. Though, again, this is all ecosystem and not language design.

Re:Java 16 by mlk on Wednesday March 17, 2021 @03:12AM (#26487535)
You'd love Kotlin then
Re:Java 16 by LordDragonfang on Tuesday March 16, 2021 @05:21PM (#26483155)
>I don't think C# has been as careful with its abstractions and the general aesthetic of the language to the degree that Java has

You say "careful", others would say "stubborn". The refusal to add things like operator overloading lead to a much less aesthetically pleasing language to read and write.

Re:Java 16 by aardvark179 on Tuesday March 16, 2021 @05:54PM (#26483605)
I can understand the resistance to traditional operator overloading, but something like implementing a Monoid interface which specifies operator methods might work. I think the sort of value types that people are likely to implement with Valhalla will make the case for this much stronger.
Re:Java 16 by pjmlp on Tuesday March 16, 2021 @02:23PM (#26480782)
They keep playing catch up with each other, in different ways across the eco-system and language features, since they exist.
Re:Java 16 by ernst_klim on Tuesday March 16, 2021 @03:27PM (#26481650)
Or just use Scala and stay on JVM. You can even easily mix Scala and Java classes within the project.
Re:Java 16 by bestouff on Tuesday March 16, 2021 @12:42PM (#26479218)
Nice, but I still prefer Rust's match syntax. It feels natural and ergonomic.
Re:Java 16 by elric on Tuesday March 16, 2021 @11:33AM (#26478161)
Nice to see that Records are finally out of preview. But note that Sealed Classes are still in Preview mode and are subject to change (or removal) in newer versions.
Re:Java 16 by krzyk on Tuesday March 16, 2021 @12:34PM (#26479088)
Removal is not likely, nor is major change. Most likely some minor changes.
Re:Java 16 by exdsq on Tuesday March 16, 2021 @11:18AM (#26477890)
Love the state machine example :)