r/programming • • Apr 16 '21

Java is criminally underhyped

https://jackson.sh/posts/2021-04-java-underrated/
41 Upvotes

220 comments sorted by

View all comments

43

u/Jwosty Apr 16 '21 edited Apr 16 '21

So this article is mainly a comparison between Java and Javascript/Typescript, with the following pro's listed for Java:

  • Good IDEs

  • Static typing

  • Good standard library

Which, I grant the author, are true -- when compared to Javascript/Typescript.

However Java isn't the only language that has these advantages. See many other static languages such as C#, C++, etc. And if you want to get the best of both worlds from static typing (correctness and safety) and dynamic typing (readability and brevity), we do have languages with static type inference (Scala, F#, OCaml, etc). Why not those?

UoC must be weird, because at my school, we mainly used Java for courses, as the sort of default choice, as many many college do... I definitely don't miss it.

Call me a C#/.NET fanboy or whatever you want, but you can't deny it's a faster innovating and generally cleaner language and runtime (generics at runtime, async/await, non-nullable types, tuples -- gosh, Java doesn't have a standard tuple type!). Checked exceptions are a disaster. And don't even get me started on all the interfaces in Java that have "optional methods" -- why include it in the interface if it's even documented that some implementations will just throw UnsupportedOperationException (I understand that some of this antipattern exists in .NET, but they're few and far between compared to Java's std lib).

In summary -- Java is just so boring. It's always the last to get modern language features; it almost never blazes the trail. Java didn't even have first class lambdas until Java 8 IIRC.... Java is criminally lagging behind. Java is death by committee in action.

19

u/Muoniurn Apr 16 '21

Well, good IDEs and C++ is a no go. Due to macro magic, typedefs and everything else C++ is impossible to write a good IDE for. Hopefully modules and modern additions will help, but older codebases will not seize to use macros for example.

I agree that C# also has great IDEs, but I still feel that idea is the best one all around. Rider is pretty close though.

it's a faster innovating and generally cleaner language and runtime (generics at runtime, async/await, non-nullable types, tuples -- gosh, Java doesn't have a standard tuple type!)

Well, most innovation happens at the platform level in Java, which makes sense considering how much code is written in it. It would be stupid to break backwards compatibility, even though some mistakes could be fixed. But similarly , this slow language level movement allows the Java team to only include actually worthwhile features (last mover advantage). For example, async-await introduces unnecessary function coloring. Project Loom will solve the same problem in a much more elegant and superior way.

Checked exceptions have some bad edge cases with lambdas, and it is sometimes troubling to add random throws clauses, but imo they are a good solution. They are basically a Result | Exception sum type incorporated natively in the language, which is pretty much the new “hype”. It is actually even better due to it also attaching proper stack traces.

And I’m not sure it has anything to do with committee, it is a pretty community-oriented process. They are just conservative on the language side. And on the platform side, it is truly state of the art, with multiple best-of-its-kind GCs, including two low-latency ones that pretty much make any sort of use case previously disallowed by world-freezes available to the platform (ZGC promises 1 ms pauses, so basically the OS itself becomes the latency bottleneck with process scheduling). Also, Graal is truly revolutionary, making actual polyglot programming possible with the same object being manipulated in python, js, jvm languages and even C/C++ with llvm.

Note: I am a java fan boy.

→ More replies (10)

28

u/chrisgseaton Apr 16 '21

it almost never blazes the trail

This is an absolutely bizarre claim, completely disconnected from reality.

I don't have any numbers, but I'd bet my life savings that Java has an order of magnitude more research papers published on it every single year than all .NET languages combined.

Java has dominated systems and software engineering research for decades. Java experiments with big new ideas in areas like compilers, interpreters, optimisation, garbage collection while .NET ships... some new syntactical sugar that everyone knew how to do anyway.

10

u/AdministrationWaste7 Apr 16 '21 edited Apr 16 '21

i see the java vs c# war continues . this feels like early 2000s for some reason lol

interestingly enough i see plenty of claims about how great and revolutionary the .net CLR is from .net people.

→ More replies (2)

4

u/[deleted] Apr 20 '21

.NET ships... some new syntactical sugar that everyone knew how to do anyway.

Right! What is everyones obsession with this async await syntactic sugar? We've been able to do this stuff for years... but suddenly now we get a shortcut and people are judging languages based on it!

→ More replies (25)

0

u/[deleted] Apr 16 '21

[deleted]

9

u/Jwosty Apr 16 '21

It's had so long to get out from under C#, too, and still hasn't. IMO the main thing the Java ecosystem has going for it is Scala, which is a legitimately awesome part of that world. Well, that, and great hot-swap debugging.

5

u/Nacimota Apr 16 '21

How do you feel about Kotlin? I've never really tried it, but the pitch there also seems to be "Java but with the problems fixed". From what I've seen, it definitely takes some cues from C# as well.

6

u/Jwosty Apr 16 '21

I've never looked into Kotlin.

However, it might be hard to convince me to use it because I've already been sold on functional programming languages with static typing, so I'm definitely an F# person. Though I understand I'm in a minority camp there, and that's okay :)

Elixir/Erlang are legitimately interesting looking to me. I've always wanted to dive into those.

3

u/Nacimota Apr 16 '21

I'm a C# person and in the past it's been hard for me to find reasons to adopt F#. That said, I find myself using functional features in C# a lot more recently so maybe I should give it another look.

I guess my point with Kotlin was that I think Java's issue is that fixing its major problems would require so many (probably) backwards incompatible changes that it might as well just be a new language at that point. I feel like that's what Kotlin is trying to be, but again, I haven't really used it personally so I can't say how well it does so.

5

u/Jwosty Apr 16 '21

So F# is in a really interesting (and frustrating) situation. Let me start off by pointing you toward some of the best things about F#:

  • Great type inference -- the language reads beautifully but you don't lose type safety at all

  • Discriminated unions and records (this lead to "type-driven-design" which often comes out very cleanly)

  • Immutability by default (which gets rid of a looooot of bugs and is make multithreading that much easier)

  • Mandatory "onion architecture" (i.e. files can only reference stuff from files that come prior in the compilation order -- this feels restrictive at first but leads to much less spaghetti code in the end once you get used to it)

  • Option types (solves the million-dollar problem of nulls; however C# is catching up with non-nullable types)

  • Type providers

  • Computation expressions

To name some. There's more.

Scala wins over so many Java developers because the gap between the two languages is absolutely huge. It solves so many real pain points, and does it well.

F#, on the other hand, also does a lot of amazing amazing things, but the problem is that C# is already a decent language in the first place. C# devs aren't often looking for something new because C# pretty much works great. There's not as much a gap between the languages, and it's narrowing, as you sort of mention.

→ More replies (7)

3

u/Clockwork_Medic Apr 16 '21

Kotlin is great if you’re already working in Java.

It takes a lot of cues from things done better in other languages, such as C# and Swift, with an added emphasis on null safety.

To Java’s credit, they do seem to be trying harder to close the feature gap with modern languages, and may one day get to the point where I wouldn’t feel inclined to use Kotlin, but I don’t see that happening within the decade.

→ More replies (1)

6

u/AdministrationWaste7 Apr 16 '21

It still hasn't managed to get out from under c# being "java but with the problems fixed"

probably because c#, as a language, is generally the better one

→ More replies (8)

12

u/pron98 Apr 16 '21

Call me a C#/.NET fanboy or whatever you want, but you can't deny it's a faster innovating and generally cleaner language and runtime

Call me a Java fanboy, but I've found the exact opposite. C# feels downright primitive, often lagging behind Java by 15 years or so. Sure it adds more features to the language more quickly, but that's because Java is against adding many features to the language; a hoarder objectively has more stuff than a non-hoarder, but that is not an objective virtue. Java innovates much more on the runtime -- in GCs, optimising compilers, and low-overhead deep observability.

2

u/couscous_ Apr 20 '21

Couldn't one argue that you don't need as much innovation in GCs and optimizing compilers given the low level access that C# gives to the user? We see this in the taken-with-a-grain-of-salt benchmarks game, where C# is faster than Java.

That being said, low overhead deep observability is just awesome.

4

u/pron98 Apr 20 '21

Perhaps, but then you could use the same argument for preferring C++ or Rust over both. Also, as far as I remember, the benchmarks don't really exercise memory management or megamorphic dispatch, and mostly measure things that aren't common application hotspots while ignoring things that are, and even then C# mostly beats Java in that game because it uses the C# equivalent of the Vector API, while the Java entries don't. Even with that extra control C# doesn't perform as well as Java when it comes to large programs that truly exercise the platform.

3

u/couscous_ Apr 20 '21

but then you could use the same argument for preferring C++ or Rust over both

The difference is that with C#, you get the benefit of a managed environment by default, until you need to go lower level for performance purposes. With C++ or Rust, you don't have that option.

Java in that game because it uses the C# equivalent of the Vector API

Yes, and also pass by ref mutable structs.

C# doesn't perform as well as Java when it comes to large programs that truly exercise the platform.

I have a feeling that might be the case, but it would be nice to see papers or studies that demonstrate this. Are you aware of any, otherwise, on what basis are you making this claim (which I am not disputing)?

It will be very interesting to see how the landscape changes once Java gets inline types.

→ More replies (2)

6

u/KronisLV Apr 16 '21

Checked exceptions are a disaster.

I actually feel the exact opposite way. Whenever i see unchecked exceptions, i can't help but to feel that noone will write code to handle the possibility of them occurring until that will happen, at which point it will already have been to late to address whatever faulty logic will happen.

In my opinion, it would be better to always be forced to handle any and all exceptions that code may throw, or to be forced to rethrow these exceptions, add them to the method signature under throws and let them bubble upwards until they're either handled somewhere explicitly (or someone just half asses it and does a catch-all of Exception).

6

u/[deleted] Apr 20 '21

Java is criminally lagging behind. Java is death by committee in action

Java users: Amazon, Apple, Netflix, Google, Spotify, Alibaba, LinkedIn, Uber, Soundcloud, and almost every government and financial institution on the planet

C# users: Microsoft, Stack Overflow, Unity

I don't know if it's wishful thinking or delusion but clearly Java continues to be the top choice of FAANG as well as many other companies whether you like it or not.

→ More replies (1)

3

u/Persism Apr 20 '21

but you can't deny it's a faster innovating

I can. Years behind Java on 64 bit support. Years behind Java on ORM. Years behind Java on MVC. Years behind Java on central package management.

Fanbois think language features are everything but there are many bad language decisions in C#.

  • Mutable Structs

  • async/await - pollutes the entire codebase

  • Properties at the language level - and still no setter overloads!

  • Partial types

  • Compiling XML? FFS

  • Brain dead enum

  • LINQ - useless training wheels

5

u/AbleZion Apr 16 '21

(generics at runtime, async/await, non-nullable types, tuples -- gosh, Java doesn't have a standard tuple type!)

Just want to add partial classes, namespaces, and extension methods!

So freaking handy. C# is honestly a dream language.

I don't dig all the freaky shorthand syntax they're putting in for some things now, but the additions are still mostly good.

2

u/[deleted] Apr 21 '21 edited Apr 21 '21

The whole point of Java is that it keeps things simple. Most things are a class/method/annotation. Once you learn those 3 things you can do almost anything. In C# you have to learn all these various keywords (virtual, sealed, partial, region, async/await ...). Basically what you criticise is Java's best trait. The only thing I'll give C# over Java is generics at runtime.

Sometimes it feels like C# adds language features just so they have something Java doesn't. Async/await is a perfect example. Its simply syntactic sugar, but people always brag about it. The Java team would rather wait to bring a better concurrency model (performance of async without the developer overhead - see project Loom).

As for Tuples in particular, they are a bad idea. Creating your own types is better.

Java didn't even have first class lambdas until Java 8

Java 8 was 7 years ago by the way...

3

u/Jwosty Apr 21 '21

I actually agree with your point that a complex language is a sort of "language design smell." C# isn't even my preferred language -- F# is, and as part of the criteria for what makes good new F# language features (as F# also has an open design process), the designers say:

Adding endless new language features in every version has major downsides. Here are some observations on why adding features is not necessarily a good thing:

  1. Stability is a virtue

  2. Gradual evolution is good

  3. Adding new language features on every version is not a necessarily a sign of strength. Many languages have spread very widely while remaining very stable (e.g. Java in 2000-2013)

  4. The addition of new features on every version can be a sign that language implementors are being incentivized (e.g. getting paid) for feature-completion rather than overall simplicity and utility.

  5. New features add learning costs to every user of the language

In contrast, features which make the language more orthogonal, simpler and easier to use are generally a very good thing.

(Look, they even mention that Java's reluctance to adopt new features at a breakneck pace as a good thing like you said :) )

But too slow can be harmful.

Java 8 was 7 years ago by the way...

Right, but Java was probably the last mainstream language to adopt them. Perhaps that was a bit too slow and is a sign of Java being a little too glacial. I understand that this particular point isn't relevant today (as Java has lambdas now, thank God), but it's a sign of a pattern when combined with other facts.

In other words, maybe the balance is somewhere in the middle here. I'd probably grant you that C# can move at too breakneck of a pace and adopt too many low-impact inelegant syntactically-sugary-features. But perhaps it's also true that Java doesn't take enough risks. No language is perfect.

(Anyway - I find it kind of funny that I've found myself in a Java vs C# battle, but so be it. The hill I'll be more likely to die on is that F# strikes a better balance than both of these languages, but that's besides the point of this conversation)

→ More replies (18)