Hacker News new | ask | show | jobs
by brap 286 days ago
After trying out many languages at many places, I reached the conclusion that Java, as weird as it may be, is my favorite language.

There were times I hated it, but turns out I really just hated messy, over-engineered legacy code and working in a gray cubicle at aging MegaCorps.

The language itself is quite beautiful when used properly and with modern features.

It just really needs a makeover and better tools.

6 comments

it consistently works and has a huge ecosystem, but "beautiful" is never a word I would use to describe java. off the top of my head:

* no type level concept of a const object (ie, you can have a const reference to a List, but never a reference to a const list). this makes const-ness an implementation detail of the class itself! so frustrating that List:add() can throw depending on the underlying class.

* lack of tuples (and no, record doesn't count). this is just a syntactic sugar thing, but I really miss it from c++ and python.

* var is far less powerful than c++ auto.

in most cases, I actually prefer the syntax of c++, which is really saying something.

> [Java] has a huge ecosystem

But does it though?

I've just taken a new job writing primarily Java whereas I was previously writing mainly python and typescript.

One of the first things I've noticed is how dead Java's ecosystem (Maven central) seems in comparison to other ecosystems like PyPI, NPM or Cargo.

(Also side note: I've published packages on each of these registries and the publishing process for Maven central is comically terrible! This has to be discouraging people from contributing to the ecosystem.)

probably depends on what kind of stuff you're working on. I mostly build web services and data pipelines on AWS, where java is still the best supported language (even if others have joined the list of officially recommended).

java might not see the same brisk pace in library development as other languages, but it's also 30 years old. aside from core issues with the language that can't be papered over by 3P libs, what's missing?

The missing constness is the biggest flaw of them all, in my opinion, especially when reading other people's code. Always having to dig deep to make sure an object isn't altered somewhere down the line gets old really quick.
> The language itself is quite beautiful when used properly and with modern features.

I respect your opinion but I wouldn't call Java beautiful (of course it depends on your definition of beautiful). It takes so much ceremony to do things you would do without any thought in other languages .

Initiating a mutable set

Python

`a = {1,2}`

What most Java programmers do

``` var a = new HashSet<>(); a.add(1); a.add(2); ```

Shorter one but requires more ceremony, and hence knowledge of more language semantics

``` var a = new HashSet<>(new Arraylist<>(List.of(1,2)) ```

I don't know if the above works but the Idea is to initiate a list and pass it into a HashSet constructor.

Similarly Java 21 allows you to model union types but doing so requires you to define N+1 classes where N is the number of union cases whereas in other languages it's as simple as `type A = C |D`

`var a = Set.of(1, 2)` works just fine in Java.
Impressively simple - though there being three ways of doing something is a complexity in itself.

Perhaps I’m being too critical.

Not if only one is the right one in all cases.

In python you can also do

  s = set()
  s.add(1)
  s.add(2)
and

  s = set(x for x in [1, 2])
But I wouldn't call that having three ways to do the same.

Disclaimer: I don't know java well, just commenting based on the comments above and my python knowledge.

In python, those give a mutable set, which is what I was referring to above. Also not to put too a fine a point, you'll never see python code like that in the wild, but even in code reviews these days, it's common to find Java code written like in my example because the syntax for sets in Java came after Java 8
Thanks for specifying, as I said I'm not a java programmer. I stand corrected.

>it's common to find Java code written like in my example because the syntax for sets in Java came after Java 8

So I think we went full circle back to GP claim:

> The language itself is quite beautiful when used properly and with modern features

:)

My bad on the mutability. As far as code like that written in Java, I don't think I've ever seen something like that in anything non-toy and I started with Java 7.
I think that's fair. As with good UI, I appreciate when I can navigate via intuition. The solution in Python is intuitive, readable, and memorable. When working in Java, I frequently felt compelled to read and review pages of docs in search of a straightforward solution. I'm a sucker for Python's syntactic sugar.
I've never seen a language have a single way to do something. It's part of Python's mission statement, but it doesn't appear to even have been a consideration in practice.
I mentioned "mutable" in my comment
> The language itself is quite beautiful when used properly and with modern features.

> It just really needs a makeover and better tools.

I love java, wouldn't call it beautiful though. But I don't need a language to be beautiful, I need it to be pragmatic, blisteringly fast, have an extensive ecosystem and top quality tooling. Java delivers #1 on all of those so I love it.

For beauty, I like ruby and lisp, but those both fail on all the other criteria so they are mostly for hobby use for me. (Python, the darling of everyone these days, is pretty much dead last on every criteria except popularity.)

> better tools

I'd say Java & JVM has pretty much the best tooling on all fronts.

I can't think of anything that has better tooling around the language and runtime.

I moved to a C++/.Net/Python shop after working with Java, and I honestly miss Java.
I can't see why you'd pick Java over C#. IMO its basically all the same preferences with slightly more consistent syntax choices. That said, Java is great too. It's underrated considering what a workhorse it is.
First, C# has much smaller ecosystem. Half the stuff I was used to have for free and a very good quality was paid and much more limited in C#.

Second, the more I worked with C# and visual studio, the more I hated it. It was pretty much the opposite with Javascript, typescript and even Java.

Well the ecosystem is different than the language but you can certainly find 3+ of any library you need in Java where .NET usually has a single choice.

I use Jetbrains for both Java and C# and the experience is essentially the same.

C# is far more complex than Java. It’s a kitchen sink language.
Did you try Kotlin ?