Hacker News new | ask | show | jobs
by ithrow 1183 days ago
In the world of web development why would one pick Java(or Kotlin) over TS/node.js ?
7 comments

I'd wager TS/node/etc going the way of PHP and JQuery in the next decade. SPA will go full WASM (which you could technically use Java for) and non-SPA will be built off better browsers (e.g. WebKit adding nested CSS) and HTMX-style solutions. Note that it doesn't mean everyone will be rolling their own WASM-based engine, but that there will be a bunch of public WASM-based engines (like PyScript/Pyodide stuff) that are tailored for specific domains than one-size-fits-all React.

This leaves "full stack JS" in an awkward middle ground. Sure, you could still use it on your backend (like PHP), but why?

We use JS because there were literally no other practical options, but better browsers and WASM are providing new options.

Java has really good runtime monitoring capability. Being able to get a thread dump from a production system, or generating Flight Recorder logs for offline analysis is incredibly useful. Is there something similar in the Node ecosystem?
Nope. You can get a heap dump which gives you object allocation stats by "object shape" which is incredibly less useful than stats by ClassPath.
It can execute application code on more than one thread at a time. Something I'd think people would appreciate in the age of many-core systems.
Java's superior G1/Parallel/Serial GC that they're changing?
I've been doing backend dev in Node/TS for the first time recently after working mainly in Python or Ruby for many years. And overall I have to say I'm not very impressed. The tools and frameworks are immature and it's annoying having to deal with all the unfixable flaws in JS.

If I were starting a new company today I would certainly seriously consider Java or Kotlin instead.

Do you mean because there's no Rails or Django for nodejs?
Yeah that and things like ORMs are less mature.
For the same reasons you'd pick golang over python/TS.

Only you'll get higher-level abstractions (pattern matching, FP-style maps/flatMaps&Co throughout the standard library) and powerful collections with full support for generics.

Better yet, start with Kotlin from day one.

At that point, why not Scala?
I personally love scala: It's been my main language at work for well over a decade. However, the barriers of entry are real, especially since arguably the most popular styles of the language demand learning the most esoteric parts of the language straight away. If your organization is well seeded with very experienced people, they'll be able to train people up, but it's oh so easy for things to go wrong.

If you are looking for all the advanced type system features, kotlin is definitely not going to put you in the same spot, but if you are hiring Java devs, training them is a far easier lift: They can mostly train themselves.

I'd hope that after another version or two of scala3, when more organizations are happy running it in production, we might have an easier onboarding road, where we don't have to explain implicit parameters, implicit conversions and implicit classes, just so that we can get to the real meat that is the mechanics of type classes. But, as is, there's good defensible reasons for many teams to go try Kotlin first.

Agreed. If somebody doesn't know Java and decides to jump to Kotlin, I will have the same question: why not Scala which is used more than Kotlin on computers (i.e. non-Android)?
I'm not necessarily advocating for Kotlin but the key argument would be supportability. Scala is a very complex language+ecosystem with idioms many people are highly unfamiliar with. Comparatively, Kotlin can be written idiomatically in a way that the vast majority of developers will readily understand and quickly come up to speed with.
Type safety, performance, more battle tested ecosystem just to mention a few points on why it's better than node.

Personally I would never trust JavaScript on backend.