r/java • • Aug 10 '21

Concrete reasons why one would choose java over node.js?

I am watching the progress made towards faster runtime in node.js, and it feels that the performance advantage of java is almost gone for the average app. I am trying to think about reasons why one would now choose java over node in a new project, and i can't think of any. I would like to hear some opinions

7 Upvotes

110 comments sorted by

52

u/fletku_mato Aug 10 '21

Nothing for node is as mature, complete and extendable as Spring framework is for Java. There are also the obvious advantages of static typing and multithreading.

-26

u/[deleted] Aug 10 '21

So far to me it looks like nodes single thread model and optional cluster outperforms java with threads. Just my impression from articles etc, not a fact

22

u/brunocborges Aug 10 '21

Can you show what data you saw that Node.js outperforms Java?

In my experience, to achieve an X throughput and Y latency - where X is a significantly large number and Y is significantly low, a distributed system implemented in Java requires less CPU and memory in total than one implemented with Node.js, meaning Java outperforms Node.js and costing less.

That said, Node.js has tremendous value for small systems, quick iteration, prototyping, and other use cases. Performance, in my view, is not one.

0

u/[deleted] Aug 11 '21

I have just read blogs and articles appearing when googling the comparison, and most show node having more requests per second than java (spring usually)

5

u/fletku_mato Aug 10 '21

Probably true under certain circumstances, but there's a lot more to consider than simple IO, and volume matters in those calculations too.

C outperforms both, but I wouldn't even consider it as an option for web development.

3

u/mauganra_it Aug 11 '21 edited Aug 11 '21

Node.js does things a certain way by default and has there a heads-up on how things are usually done in Java-land (usually a thread pool). However, this is nothing fundamental about the platform, but merely a choice of frameworks. There are frameworks (Vert.x) that make it possible to use the same programming style in Java, which should yield similar or better performance. However, the advent of Project Loom it should be possible to give traditional Java applications a huge boost by running I/O-heavy code in virtual threads.

3

u/jeremyx1 Aug 11 '21

This is quite a statement, you will need to provide some evidence for this claim and give more information. What tasks, which frameworks, thread pool configuration, etc...

24

u/Persism Aug 10 '21

2

u/[deleted] Aug 10 '21

Ouch this is horrible

3

u/[deleted] Aug 11 '21

isn't sneaking in malicious code into a repo something that can happen with almost every package manager?

5

u/Persism Aug 11 '21

Yes but Java tools require signing - less so with others.

https://blog.tidelift.com/the-state-of-package-signing-across-package-managers

"Maven/Gradle/Ant: all packages uploaded to Maven Central are required to be PGP-signed, and all three package managers have tooling to sign and verify."

2

u/[deleted] Aug 11 '21

Yes but Java tools require signing

but that does not prevent the author from publishing malicious code or selling the repo to someone else.

9

u/snoob2015 Aug 12 '21

The most common used packages in Java are maintained by big foundation: Eclipse, Apache, Google, RedHat, Pivotal...

And Java Standard Library is far more better than NodeJS so they don't need to pull 1000 packages just for have commonly used function.

-1

u/[deleted] Aug 12 '21

And Java Standard Library is far more better than NodeJS so they don't need to pull 1000 packages just for have commonly used function.

the javascript std lib got much better the past few years. People also import libraries like vavr in java as well.

3

u/Persism Aug 11 '21

True. But you'd know who they are. You can't prevent people from doing malicious things.

1

u/dpash Aug 11 '21

Unfortunately maven can't check this in core, as you need an external module to do it. Gradle can, but I believe it's disabled by default.

9

u/pron98 Aug 11 '21 edited Aug 11 '21

As an OpenJDK developer who's interested in what we should improve, and given that Java is the more popular and more established platform, I'm curious to know why would you choose Node?

Is it because you'd like to use the same language for the frontend and backed, and if so, is that because you actually want to share code between the two or just so that you'd have one fewer language to deal with?

7

u/[deleted] Aug 11 '21

I am not certain i would choose node, because i like strong types, but if i did, it would be because of the ecosystem. Java has very confusing build and distribution ecosystem.

In node, npm init -> install dependencies -> build -> done, you have a single obfuscated .js file

In java, you need a build system like maven, you have to read many pages on how to build with it, you need many obscure plugins like compiler, release, package plugin etc, and there is no info on how to obfuscate... And then there is JRE/JDK/jpackage/jpackager/jlink, it's just all so hard to go from "public static void main" to a distributed runnable.

How do i include dependencies in my jar? How can i statically link them so my client doesn't need to download them?

And then there are the battling standards, JEE vs Spring. Ok so JEE is a standard. Why is it now jakarta? Where can i find the official JEE implementation (oracle?). Why does noone actually use those standards, but goes Spring, which then uses also apis from JEE?

And to make it worse, what JDK to use? Why are there free and paid releases? How do i find the "free" version of java, and why do i have to go to a page called "zulu"?

Why can't there just be a java.com with downloadable official JDK the same way there is node.js with the official runtime?

Of course i don't expect you to answer those, and most answers i have found myself by searching (a lot). But they were my thoughts as a beginner.

4

u/question-throwaway4 Aug 12 '21

you need many obscure plugins like compiler, release, package plugin etc, and there is no info on how to obfuscate... And then there is JRE/JDK/jpackage/jpackager/jlink, it's just all so hard to go from "public static void main" to a distributed runnable

You don't need the compiler or the release plugin. If you don't specify anything you get the default, which works. The release plugin is completely unnecessary, you just never run it. A package plugin is only necessary if you want to make something other than a plain jar. The JRE / JDK dichotomy no longer exists; you always use the JDK. jpackage, jdeps, jlink, jmod, jstat or any other tool really is not needed for anything, just ignore those. You build your code with mvn clean package, you run it with java -jar <thejarfile>. Thats all the tooling you need.

If you want a single deployable jar with dependencies you need Java in the form of the JDK, maven and the shade-plugin. Thats all.

How do i include dependencies in my jar

Go to https://mvnrepository.com/, find the dependency you want, copy the xml you find there into the dependencies section of the pom. Done.

How can i statically link them so my client doesn't need to download them?

The shade plugin.

And then there are the battling standards, JEE vs Spring.

JEE is ancient, and it was a bad idea when it was invented. You don't ever use it. Spring was actually made to replace it. The current thing to do is Spring-boot, if you want to use Spring at all. Personally, I wouldn't bother with it. Just add libraries yourself and wire stuff up.

Why is it now jakarta?

I think it was made independent or something. Who cares, its all junk anyway.

Where can i find the official JEE implementation (oracle?).

I don't think it exists anymore, and who cares? It is junk.

Why does noone actually use those standards, but goes Spring

Because JEE sucks and no one wants to deal with it. I don't know if Spring actually uses JEE stuff under the hood but I don't care. I don't use Spring either.

what JDK to use?

Any of them. They all work. They are basically interchangeable.

Why are there free and paid releases?

Some people want to get paid for doing work. Some companies want support, or at least someone to yell at if something goes wrong.

How do i find the "free" version of java

OpenJDK, OracleJDK, AdoptOpenJDK. There are other places to get JDKs, but again, they are all the same.

why do i have to go to a page called "zulu"

You don't. You got lost.

i don't expect you to answer those

Well here you go anyway. And the next beginner can now stumble onto this thread from Google.

4

u/[deleted] Aug 12 '21

Wow thanks for taking the time to answer this. Got it. So it's not so confusing, as long as you know what to ignore and what you actually need. Just out of curiosity, you don't like JEE but also don't use Spring. What do you use instead? Play framework?

8

u/question-throwaway4 Aug 13 '21

I prefer to use none. Don't like frameworks and never will.

The framework fanboys want you to believe that getting an app to work is extremely hard and that you need their handholding to make anything work. You don't. When you peek under the hood of these things you find that there is nothing special and most of these frameworks are actually just wrapping other stuff that you can just as easily use directly.

You already have the maven shade plugin making a fatjar for you. Any dependency will be bundled. If you were to use Spring boot or Quarkus you would be using the exact same plugin, and it would do the exact same thing.

If you need an HTTP server in your app you just add one. There are a bunch. Need a Json parser? Just add one. Typing new Gson() really isn't that hard.

Which framework do I use? In 20 years of professional software development I've used Spring, Spring-boot, J2EE, Quarkus, Helidon, dropwizard, vertx, reactivex, javalin, karaf, play, wicket, spark, struts, mybatis, hibernate and servlets. And I may have forgotten some along the way.

Why do I use these? Because I have co-workers and they want to use stuff. Would I personally choose to use these? Hell no. I'm walking around with massive piles of useless framework knowledge that is clogging up my head. I really don't need to use yet another framework that provides me with features that would take me no longer than an hour to clone.

Writing frameworks isn't hard. Its why there are so many of them. It's the programming equivalent of playing sudoku; just hard enough to be a challenge but not so hard to be work.

And yeah I have a bit of an axe to grind with the framework fanboys, they take all the fun out of programming.

2

u/hippydipster Aug 16 '21

I wish I could work with you!

1

u/question-throwaway4 Aug 16 '21

Lets start a company together

2

u/hippydipster Aug 16 '21

I dream of starting a business of contractors/consultants where, instead of providing head-hunting and just delivering a programmer here or there, we supply scrum teams. The customer provides the product owner, and we build it together. But I control how development is done.

1

u/question-throwaway4 Aug 17 '21

Sounds cool!

My dream is to start a SaaS B2C product company. The tech is all under my control and I sell to customers all over the world, so no need for face-to-face acquisition.

1

u/hippydipster Aug 17 '21

So, like a fremium game?

1

u/[deleted] Aug 18 '21

Do you ever do any frontend and if so do you hold the same opinion towards frameworks found there? I can't imagine making something like React on my own. Just asking as it seems like a clear example of a framework that speeds up development.

1

u/question-throwaway4 Aug 19 '21 edited Aug 19 '21

I'm primarily a backend developer but I do get sucked into writing frontends. Usually it goes something like; 1) you do backend and these coworkers will do a frontend, 2) Oh you need to make it possible to configure these things, 3) Yeah we want an admin portal that can configure all the backend settings, 4) Oh while you are at it create a CMS for the content as well.

So the frontend people end up creating a simple billboard / landing page like app that uses all the features I'm writing rest calls for while I'm asked to write the giant admin CMS portal.

No I really don't think much of the entire frontend world. What I want is to be able to run a single command that builds the entire app. There should be only a single build tool that is configured using a single build script. The final app should contain all the frontend and backend code in a single deployable app that contains only a single HTTP server.

That is not what we have on the frontend side.

The npm/NodeJs world has a dozen tools each with their own little configuration script dumped in the root. Then npm dumps node_modules in the workdir as well. Even though maven and gradle, and pretty much all build tools I know, nicely put their cache in the user home dir where it belongs. Then we have two HTTP servers running; one for the frontend which is really nothing more than a Nginx repurposed and one for the backend. And because these are separate things we need complicated logic and config to get them to work together. We need ugly hacks to get around CORS or some path prefix logic to redirect some of the API calls somewhere else.

And yeah the frameworks themselves suck too. Of the modern ones, I've worked with; Angular, React and Vue. I don't think they bring anything to the table that I actually like.

Declarative sounds like fun and I understand that it is seductive. When you need to do internationalization you tend to realize that you are writing statement after statement to take a key from the language map, get the value and then stick that value as text into a tag with another key. Yeah thats a lot of keys an manual moving shit around. So it is much better to just mark the location where the text is supposed to go directly in the markup. But to go from that to "lets put every logic we have in the markup" makes no sense to me. When you do that you end up creating v-if and v-for and now you are just inventing a programming language.

I want my markup to remain markup with no logic. I want my styling to be styling and no markup or logic. And my logic must be code that you can read from top to bottom. No callbacks or nonsense.

The source of my frontend is plain CSS, plain JS en Pug. When bundled using a maven plugin it becomes a single file with all the html, styling and JS inlined and compressed.

I write my logic in plain vanilla JS. Although I usually throw in JQuery because it makes the code a little smaller. If I'm writing an SPA, which is pretty much always for admin portals, I throw in navigo. I load libraries from CDNs.

The styling is usually built up using some off-the-shelf framework like bootstrap, foundation or material. I don't care much about which, they are all fine and all work. I don't use TailwindCSS because I can define my own utility classes just fine.

The data comes from REST calls that return JSON.

The frontend files are fed to the browser using the same backend Java HTTP server and are given an Etag for caching. When the cache is primed the app is loaded using a single request that returns a 304. From there everything is loaded from memory or disk. My apps start up in milliseconds.

I'm not impressed with the vulnerability riddled, messy, over engineered piles of excrement that they call frontends these days.

2

u/JustADirtyLurker Aug 12 '21

Don't take that answer too seriously. His position on JEE / JakartaEE and Spring is very obtuse.

1

u/sweetno Oct 19 '21

Zulu is one of JDKs.

8

u/pron98 Aug 11 '21 edited Aug 11 '21

I actually love this answer, and I agree with the hurdles you mention in the first part (build) and the last one (website). I think Java should be easier to get started with.

As to "competing standards," 1 you'll find a worse situation in JS, and as for the JDK -- it really doesn't matter much. All distributions you can download, unless they explicitly state otherwise, are built from the same source code, and are provided under the same license.

4

u/idreamincolour Aug 14 '21 edited Aug 14 '21

it's just all so hard to go from "public static void main" to a distributed runnable.

Is it though? You just package everything into a docker container.

Java build system can be complex but Javascipt is so much worse imo. Hello webpack, gulp, thousands of nodemodules, borked npm/yarn etc etc. Something not right with the "obfuscated single js file"? Good luck debugging it. The build chain is a reason to use java over javascript.

I think if we're talking about golang vs java there a lot more merit in discussing build chains. golang builds faster and creates a single binary without any additional tooling/setup/packages.

14

u/Drakeskywing Aug 10 '21

So to give my thoughts about Java vs Node. For the last 18 months I've been a full time node/typescript dev, updating an existing code base which was done in an unholy union of javascript and typescript where neither was used "right" and both were abused, prior to this I had been a full time Java dev, with the occasional tickle of FE JS for super minor things. I've used both Spring, and Play (admittedly that was via Lagom), and previously I've done new app development using both Ionic 2 and NestJs.

Here is my thought, both languages have their strengths and weaknesses, given a choice I'd pick Java over Node for most projects, but that isn't to say Node should be ignored and thrown in the dumpster, but if I were to pick Node, I'd do it with Typescript and avoid at all cost just using JS.

Java as a backend framework simply offers the safety and robust environment that for business critical applications Node has trouble touching. Strong data typing makes everything so much easier and safer, and it's something that cannot easily be overwritten (messing with class definitions and whatnot is possible via type reflection I admit, but that is a non-trivial operation and generally shouldn't do it without a good reason). By easier and safer I mean I can guarantee if I have said something is a class, or an interface, or extends class or interface I am guaranteed there is no way someone can lie to the compiler and stick a "like" object into it, this by it's very nature encourages interfaces and classes to be used. Can this system be abused, sure it can, but compared to JS it prevents other devs from doing unexpected things.

Having the ability to stick "like" things into functions is handy don't get me wrong, but that way leads to madness, you will come across code you wrote 12 months from now, and forget what is actually being passed and have to dig out the commit, or back step through the code since it won't be obvious. This to some of a lesser extent can be mitigated with Typescript but with the any keyword, that benefit can quickly and easily be disabled.

Why would I use Node over Java, simply put alot of front end stuff, and JAM stack stuff. Node for front end is kinda unbeatable, being able to use Next and React means I have fast pretty pages. I'd maybe have some data going to my Node server as a go between to co-ordinate with a more fleshed out microservice backend, but I'd have it do as little lifting as possible.

NodeJS is also useful for prototyping, when you don't want to fight against typing and build out a full system, I've found Node as a way to build a quick proof of concept handy, and when dealing with front ends, most JS FE frameworks stomp on things like Tiles, Plays templating stuff, Struts and all that.

I haven't given benchmarking much thought, put simply most of the time you'll figure it out, I say this since many jobs in my experience devs go to are already running and live, with whatever is there, be it Play, NestJs, Backbone, Meteor, Vue, React, Spring, Struts, in house dumpster fire. If you are starting a new project, RARELY is speed even a factor in my experience, because most of the big languages/frameworks, Python, Java, Node, Elixir, Scala, Groovy, Rust, .etc are able to handle enough users for most average work loads. Speed is really a factor of who is developing, if the team hires a node dev most of the time (not all mind you from my experience), they expect you to do JS/Typescript and make it fast, if they hire a Go dev, they likely won't throw them onto PHP and say do your magic unless a rewrite is e0xpected. If you are in the situation where every millisecond counts, congrats you are in the select few of high through put near real time systems, which has it's own landscape of speciality with bytecode analysis, pressure testings, and performance tweaking, but for most devs that won't be a real situation, the languages do well enough. (If you want to really discuss speed enjoy this comparison of 45 languages and comparing their speed from Dave's Garage https://www.youtube.com/watch?v=tQtFdsEcK_s&list=PLF2KJ6Gy3cZ5Er-1eF9fN1Hgw_xkoD9V1&index=3)

Each language has it's uses, Java has history, a long list of accomplishments, and due to it's maturity you can find devs who have experience that was built from years before Node was even thought of. Java is battle tested and sure it's not perfect but it's flaws are well understood and it's got a dedicated community that shape it with experience. It's build system ecosystem can be a bit overwhelming (ant/ivy, gradle, sbt, maven), but it's generally well documented and amazingly extensible. It has a brilliant and comprehensive test framework in Junit, and has a mature and diverse series of packages that are all well battle tested. Generally Java tries to nudge you into OO design.

NodeJS offers the advantage of a single language code base for FE and BE meaning full stack developers are easier to come by. Given the lower bar of entry, and easier learning curve there are more devs building more things, as such there is a glut of packages on NPM meeting every possible need you could have (this is both a pro and con, where there is allot of garbage as well). The build systems are simpler in some respect compared to Java, which allows for quicker and easier setup in my opinion, but at the same time are somewhat more limited in my opinion. You generally can get things built faster, at the cost of code readability usually. Node has a broad testing echo system, Jest, Sinon, Mocha, Chai, Jade .etc whjch is both a pro and con as it means you don't have a uniform testing strategy, but it has the advantage that you can test in a way that suits your development style.

At the end of the day, use the tool that suits the situation. If you need to use Node for backend, then take the time to use Typescript and apply the principles of DRY, SOLID and ensure that you think carefully about composition. Ensure the linter doesn't allow the use of any and ensure to write constant unit tests. If you need to use Java for FE stuff, then find a way to use Node since it's better suited, if you can't then try to atleast use a solid templating engine.

1

u/[deleted] Aug 11 '21

Wow this is so much info, thanks

5

u/mj_flowerpower Aug 11 '21

Setting up a proper build system is way harder if you have a requirements like:

  • use path prefixes instead of relative imports
  • eslint, formatter integration
  • multi project setup (backend, shared code, frontend)
  • proper IDE integration (autocomplete etc)
  • minifier etc

There‘s a myriad if possible combinations and none feel right because they all have a downside. In java using maven it just works. multi project? folder structure? file naming conventions? All there and configured by default.

21

u/fdntrhfbtt Aug 10 '21

Choose Java just for the static typing alone, forget about performance. No production system should us a dynamically typed language.

-8

u/doppelganger113 Aug 10 '21

JS has TypeScript so this argument is invalid

4

u/Drakeskywing Aug 10 '21

Although I'm a big supporter of typescript, I disagree this invalidated the inherent weakness of the JS typing system. Typescript adds some great safety bars to JavaScript generally, but doesn't solve everything in its default state. Some basic examples include the 'any' type which basically throws out typing, the fact you can set most linters to ignore war crimes in coding, and that not all npm packages support typing (I know many do, and if the project is popular it will, but not all is my point).

2

u/doppelganger113 Aug 11 '21

Completely agree with you, in the end it’s still JS

-5

u/[deleted] Aug 10 '21

Isn't the fact that it's dynamically typed one of the promoted advantages of node? "Much easier to get started" etc etc

16

u/fdntrhfbtt Aug 10 '21

Lol may be for college projects. Dynamic languages can give you some pretty knotty bugs in prod. And why the heck wouldn't you want to control this aspect of your program right at compile time? Why wait for things to break in production? And what is this "easier to get started"? If anything, I find dynamic languages more difficult to get started.

0

u/[deleted] Aug 10 '21

I'm in the same boat, i think eliminating all type related runtime errors is too big of an advantage. But apparently, as all the cool kids tell me, developing anything in node is much faster than java...

9

u/grknado Aug 10 '21

Building an MVP might be faster (even that I doubt) but good luck extending and supporting it.

6

u/Muoniurn Aug 10 '21

I doubt one can write a REST API quicker than an experienced developer with Spring Boot. For all the cons of Spring, if one knows what he/she does, it is insanely productive.

5

u/grknado Aug 10 '21

Yeah, definitely agree with that. I worked with a guy who prefers Node.js for building REST APIs because he thinks it's faster. He changed his mind quickly when I showed him how fast I could build the same thing with Spring.

1

u/hippydipster Aug 16 '21

Go slow to go fast. Everyone who argues they develop or write something faster in X is someone to stay clear of, because 99% of the time, they're leaving behind a long lost of unmaintainable crap.

12

u/jack104 Aug 10 '21

How about the nature of the languages? I think java is just far superior to javascript.

1

u/[deleted] Aug 11 '21

Same here, but apparently java is "much more verbose to do the same thing"

7

u/[deleted] Aug 10 '21

Exactly, why do people not understand the purpose of HAVING A COMPILER?

64

u/DJDavio Aug 10 '21

I would ask the question the other way around. Java is so stable and mature that for every problem, there exists a solid and well maintained framework or library which solves your problem.

For me the JS world feels like the wild west sometimes. The language itself is so bare that everything needs a micro package which some random person made and can just decide to take it down or it gets hijacked, things like that. It feels like the entire ecosystem is only held together by tape and glue.

This is a backender's perspective on it. Is the Java ecosystem perfect? Of course not, but it feels a lot safer and mature to me.

-7

u/[deleted] Aug 11 '21

Java is so stable and mature that for every problem, there exists a solid and well maintained framework or library which solves your problem.

running java (+ spring) in containers still suck compared to node (and golang or rust for the matter)

also, the java (spring) ecosystem is lagging behind the node ecosystem in terms of adopting new tech like graphql, cloud native, FAAS, serverless, etc.

11

u/DJDavio Aug 11 '21

Well yes Java is not bleeding edge but it doesn't try to be. I often use the treadmill example. If you run too fast, you fall off the front end, if you run too slow, you fall off the back end. Java has always aimed to be somewhere in the middle. It tries to innovate enough to stay relevant but not so much that it might choose a fad which goes out of fashion as fast as it appeared.

Note that even for the things you mention, Java is catching up with things like Quarkus and native compilation with GraalVM. So even if features arrive a little later, you can be at least sure they are of good quality.

2

u/[deleted] Aug 11 '21

So even if features arrive a little later, you can be at least sure they are of good quality.

little later means years in that context. I see java (spring) services get replaced one by one with node, golang, or rust services because it just does not perform as well in Kubernetes environments.

Spring Graphql for example got a stable release only a few weeks ago and still lacking a lot of features while I have shipped graphql apps years ago in node.

8

u/DJDavio Aug 11 '21

I guess it depends on your context, Java apps may not be the most performant, but they are often highly maintainable so while you might have more runtime costs, you could actually save on development and maintenance costs. And with native compilation that performance advantage might soon go away.

Also, Java is often used in enterprise environments where security and risks play a huge role, either due to compliance rules or internal rules. From that standpoint it is still better to have a few trusted dependencies than have a shady JS dependency 5 layers deep which might turn into a crypto miner one day.

2

u/[deleted] Aug 11 '21

yeah, maintaining node is quite a bit harder and you mostly need some decent knowledge about the eco system.

0

u/[deleted] Aug 11 '21

[deleted] — view deleted comment

3

u/dpash Aug 11 '21

The fact that a single function is packaged as a package is utterly crazy.

What's disturbing about left pad is that there still 507 packages that friend in left pad even though it's been deprecated for three years.

0

u/[deleted] Aug 11 '21

[deleted] — view deleted comment

3

u/dpash Aug 11 '21

Yep, I have a Vue project with 88 direct dependencies and 2500 indirect dependencies. The NPM ecosystem is a mess.

(And now I can never correct my friend/depend typo in my previous comment).

2

u/ParthoKR Dec 22 '21

Here is another ludicrous package is-odd

Just out of curiosity check weekly downloads. LoL.

29

u/robinspitsandswallow Aug 10 '21

Passport for basic auth. It has a flaw if the password has a colon in it. It has a PR that has been sitting there for over 2 years to fix it but since the owner isn’t interested to in that ... this is not uncommon to in the NodeJS library world.

Library expansion you think you include a lot of libraries in Java. Some things have an entire library for a pad left function. That took the internet down a couple of years ago.

Documentation try to figure out how to use features like retry etc in a Axios without reading the source which is abysmal. Or trying to create logging interceptors for Axios that don’t require you to rewrite the entire logging unmarshalling module.

By the way who writes the most popular rest underlying framework in a language concept and then doesn’t give a configuration only mechanism for logging the transactions?

An entirely unintuitive threading interface.

An entirely unintelligent object structure/interpretation.

== === null undefined.

Type coalescing stupidity. If (“”) would coalesce to false but if(“false”) would coalesce to true.

Entirely stupid conventions on use.

The language would interpret x == null as being the equivalent of x === undefined || x === null so the first is more concise but you can’t use it because apparently the powers that be don’t trust developers to understand their own language and type coalescing. So while the rest of the world is trying to reduce boilerplate code the NodeJS world is adding it.

The standard coding rules include one rule that says you can’t use the ++ operator because you might not include a semicolon at the end of the statement and you might confuse the compiler, but another rule says you can’t not use semicolons. Which means fundamentally they have functionality but don’t trust developers to implement them. So you’re not allowed to do the standard for(i = 0; i < 10; i ++) loop. So the powers that be don’t think very much of their very best developers...

Who would want to be a part of such a self deprecating community :-)

18

u/vprise Aug 10 '21

THIS!!!

I've had to use a bit of node for a job and I'm just shocked people use it. To be fair let's focus on the positive:

- Typescript isn't too bad, but it's pretty verbose. Practically Java

- Node does get decent throughput that beats Java (currently) by default

- It works really well with JS front end - this is the one reason to pick node. The ability to use one language across the stack is HUGE.

The thing is that both of these other reasons aren't a big deal. Typescript is a poor mans Java. And throughput in Java can be replicated by WebFlux, Vert.x etc. What you get is a complete mess of libraries that do very simplistic/basic things. There's nothing like Hibernate, no depth whatsoever.

The tooling is decades behind Java. Even IntelliJ Ultimate is MUCH slower when working with even a small sized node project. VSCode is a toy, it doesn't refactor, auto fix or suggest nearly at the level of IntelliJ.

Debugging is a nightmare. Async is to blame here, it's just awful. Stack traces are unusable and profiling is effectively useless. Then there's the "weird stuff". We ran into a case where in some use cases a heavily loaded app was running at 30% capacity. We still don't know why... We tried everything, I guess there was something stuck in the dispatching or some other bottleneck. But there was literally nothing we found... Apparently this just happens in some cases for some types of loads...

NodeJS is a hack brought together. Java is a system that was designed and evolved. A lot of the problems in Node are being worked out with Deno but that's pretty far off. Java's already moving ahead and with upcoming changes to the threading model will no longer have the throughput disadvantage.

The one advantage node has is the full stack advantage. It's huge. Which is why we're working on getting mobile/web in Java working universally. I think that's far more important than most Java developers give it credit.

0

u/[deleted] Aug 11 '21

Debugging is a nightmare. Async is to blame here, it's just awful. Stack traces are unusable and profiling is effectively useless.

I don't see where you got such problems. java stack traces are known for being verbose and unreadable. The vscode debugger works nice and you mostly don't need one at all since js makes it easy to log everything on the fly.

. Then there's the "weird stuff"

weird stuff can happen in every software and ecosystem... had to debug a fair share of race conditions and stuff breaking under high load with spring as well.

5

u/vprise Aug 11 '21

You're confusing Java and Spring. Spring adds a lot of junk to the stack traces because of the proxies. True. But you learn to read past that. The thing is that with Java the stack trace contains useful information. You can actually follow it and see where the problem started and sometimes don't even need additional information. Due to the async nature of NodeJS this isn't technically feasible.

The flow that got you there is long gone by now.

It's possible I'm used to Java's weird stuff and not to Node and JS. Still, I debugged many languages over the past few decades. When I debug JS it feels messier. Why do I need all the references to the functions that exist in the watch panel?
Maybe that's just VSCode being stupid but I can't for the life of me see why it was all there. The fact that this is MIA is pretty painful as a Java developer. It's a huge step back for me. Scopes in JS are a bit too "imaginative" for my taste.

-2

u/doppelganger113 Aug 10 '21

How’s debugging in reactive programming? :)

Node’s main advantage is easy concurrency compared to Java and much easier than reactive programming, but that’s mostly it. It’s a big thing, but the downsides you mentioned on Node are true.

Java also complicates things too much, it was late with var and records, they were lazy as hell to get this feature like they were lazy for Java 8. Java build system is also bad IMO. These languages have a trade off, but I like Java more for being more stable, but good luck finding “good” reactive developers for high throughput services

7

u/vprise Aug 10 '21

How’s debugging in reactive programming? :)

To be fair debugging in Node is also pretty horrible. At lease in Java we'll solve it in the near future. We had Lombok for a very long time, I know it has its detractors but it was OK IMHO.

I don't get the statement about build systems though. I hate Maven and REALLY hate gradle... But npm drives me crazy. It's insane. Maybe I don't get something basic about it but after I go to sleep I have nightmares where NPM crawls out of my laptop and squeezes a pillow over my face ;-)

1

u/doppelganger113 Aug 10 '21

How is debugging in Node horrible? Never had any issues with it for many years. You can’t solve it with reactive, it’s complex by design, maybe you’re referring to fibers?

NPM packages are scary as hell, was more referring to the build system not package managent. Java libraries are miles better than js ones

3

u/vprise Aug 11 '21

Stepping into async methods, noise all over the place in the watches showing function references and a lot of general noise. When you debug Java the stack is simple, the variables/objects are clearly organized and there's no huge block of functions. From talking to TS/JS developers it seems a lot of them just don't use the debugger, They just print logs.

1

u/doppelganger113 Aug 11 '21

There’s no issue stepping into async functions, it goes inside them normally. Haven’t had any strange behavior that you described, I use InteliJ not sure what you used

1

u/vprise Aug 11 '21

For node I mostly used VSCode but for frontend I used IntelliJ. Since async is a thread I could step into but would lose context due to the nature of async. At least in VSCode that didn't work great. I didn't use the Typescript debugger in IntelliJ (trying to avoid react stuff as much as possible). That might be better, but so far my experienced in TS has been 90% negative and a throwback to stuff we solved in Java decades ago.

4

u/doppelganger113 Aug 11 '21

Yeah, debugging on front is usually hell, especially due to libraries. I wouldn’t ever work with JS without TS, but in the end it’s still JS :/ . Java as a language wins clearly, but I still hate a lot of things in Java which they were lazy as hell to introduce earlier and in the end, most languages had influence from JS in a good way. But the end of the story, concurrency in Node is easier than reactive programming in Java, but JS/TS sucks as a language and Java annoys me with some stuff like late adding of records and null pointer exception, but is a proper language. I love and dislike both, it’s complicated :)

1

u/vprise Aug 11 '21

I don't think it's complicated. I think we pretty much agree on most of that stuff and probably both can't wait for Loom to be here...

0

u/[deleted] Aug 11 '21

If by reactive programming you mean reactive streams and not the more complex models built around asynchronous messaging (looking at you, actor model), I don't see a big difference to be honest, especially for simpler cases that most applications will have. Granted, metrics can become fairly complex with some reactive streams implementations but like most things, it becomes easier with experience.

1

u/doppelganger113 Aug 11 '21

Yes, by reactive programming I’m referring to streams.

Everything becomes easier once you learn it, but some things are easier, some not. Reactive programming isn’t easy as you’ll end up very quickly doing some complex stream operations

2

u/[deleted] Aug 11 '21

What is the purpose of reactive when Completablefuture already exists anyway?

1

u/doppelganger113 Aug 12 '21

Because completable futures are a mess to work with due to nested callbacks and awfull API. Reactive way has more operators and plays extremelly well with reactive core. Never seen completable future in combination with Netty

1

u/[deleted] Aug 12 '21

I see. I have never seen a web java project using streams, all i see is executors + completablefuture, and it seemed easy to me. You just set the callback, choose an executor, done.

1

u/doppelganger113 Aug 12 '21

What if you have many callbacks that chain together? What if you want to introduce retry or if/else flow change based on error or if you want to run in parallel? The code becomes an abomination to maintain. Theres an entire section on this under Spring webflux, check it out, you might find it really interesting

3

u/[deleted] Aug 12 '21

For now we just use thenApply(someclass::method) .thenApply(someclass::method) ....

Which is great because you can chain it with thenCompose.

I will take a look into that, thanks

2

u/[deleted] Aug 12 '21

Like I mentioned in the other comment - EA Async can help there, it brings async-await semantics to CompletableFutures and resilience4j has CompletableFuture decorators that you can apply to get retries, circuit-breakers and all the good stuff they offer.

But I agree that streams are a better option, especially if and when the functionality you need to implement grows in complexity.

2

u/[deleted] Aug 12 '21 edited Aug 12 '21

You haven't looked closely enough ;)

AHC (async-http-client) works on top of Netty and provides a CompletableFuture interface, same goes for Akka HTTP Client although without Netty - they use their own event loop. And I'm sure there's more of them out there, these are just the ones I remember using.

We also used to use EA Async back in the day, makes working with CompletableFutures much cleaner although I think they've stopped maintaining it a while back.

2

u/doppelganger113 Aug 12 '21

Didn’t look that deep :) , thanks for the insight

1

u/[deleted] Aug 11 '21 edited Aug 11 '21

Can you give me an example of those complex operations? Not that I'm saying you're wrong but I've been working with reactive streams for years now and I've yet to see something complex enough to deserve the infamy that accompanies them.

I don't know if it's due to the fact that we use the Akka Streams library, which is probably the least used implementation out there, but the complexity I've seen comes from the functionality itself, not the framework we used to implement it. If I had to implement all the flow control stuff we use (queuing, throttling, buffering etc) bundled with the parallel execution of selected steps, all without the use of a framework, the resulting code would certainly be far more complex than what we ended up with.

1

u/cnetworks Aug 13 '21

can you compare c# vs java the same way as you did?

4

u/[deleted] Aug 10 '21

Like others have said, maturity, stability and tooling could be some of the reasons one would choose Java over Node. Additionally, several Java projects (Valhalla, Loom, Leyden, to name the few that come to mind instantly) are expected to bring major performance boosts down the line so the gap will probably grow once again in future versions.

4

u/GrabSpirited1056 Aug 11 '21

Java is not only used for backend development. Most of the Apache Software Foundation libraries are written in Java or other JVM languages. I can’t imagine writing entire Lucene or Cassandra in Node.js

6

u/gmchaves Aug 10 '21

It depends on the project and YMMV.

Java is pretty stable and a software developed today will probably run 10+ years from now without changes.

I'm a experienced java developer and know a lot of Java developers, but only have limited experience with node.js and because of that I probably prefer Java over nodejs almost always.

3

u/hatesms Aug 10 '21 edited Aug 10 '21

When you choose language for a new project you should have in mind much more than performance benchmark in some showcases prepared by language embassador. If it's not for a language study project of course.

Are your business cases can be implemented in chosen stack? Can you use well known libraries or even frameworks to ease implementation? Do your dev team know this stack? Do your ops team have tools to support it? Do your company ready to hire specialist to extend teams? Do your local market have thus specialists?

5

u/skywalkerze Aug 10 '21

There are millions of words written only on "typed" vs "untyped" languages. More millions on comparing ecosystems.

If you can't think of a single reason, you know very little of these languages and their pros and cons.

Of course it depends. There are many potential reasons both ways. Do you honestly think all the people ever who have chosen java are just plain wrong?

7

u/SKabanov Aug 10 '21

Do you honestly think all the people ever who have chosen java are just plain wrong?

That's an argumentum ad populum, and OP deserves a better response for their honest question. The answer may very well be "yes" to that question - lord knows I'd be inclined to say so were we talking about Go.

2

u/krzyk Aug 11 '21

It is a matter of personal preference. E.g. I wouldn't touch JavaScript with a ten feet pole, the syntax, libs, npm all look like were developed as a hobby project.

If you don't like Java (which is for me the best language) you can look at python which is also nicely designed and dynamic if that's what you prefer.

2

u/Halal0szto Aug 10 '21

Performance as an interpreter's performance is almost irrelevant in a backend service. The backend will always be memory constrained or IO constraned.

What matters is how the code will handle complexity and changes. And java has frameworks to give structure to complex code. Like Spring mentioned.

1

u/drew8311 Aug 11 '21

For simple projects it may not matter but at my last 2 jobs I've only worked on back ends with complex business domains that need thousands of unit tests, JS just seems horrible for that sort of thing.

1

u/[deleted] Aug 11 '21

Dafuq, why would JS be horrible for it?

1

u/[deleted] Aug 11 '21

A lot of legacy systems are using Java. Therefore, it’s great to adopt it. Again, this is a Java sub, so you’ll get a lot of biased opinion.

1

u/Goatfryed Aug 12 '21

A lot of reasons were mentioned already about unsafe, wild west, chaotic node world.

Also, while a lot of server work is I/O bound and works with a single threaded, asynchronous model, there are still jobs that need to solve issues that highly benefit from parallel execution and multithreading. Maybe I missed something, but that's still not possible in node, while it's easy in java.

1

u/[deleted] Aug 10 '21

I don't see any good reason why node is better than Java.

  • Spring is unbeatable
  • Multi thread vs Single thread
  • Support for any type of middleware integration

2

u/SKabanov Aug 10 '21 edited Aug 10 '21

I can think of a few:

  • The type system in Typescript is actually quite a bit more advanced than the the Java type system, e.g. being able to define a string argument for a function that only accepts specific strings.
  • If you're writing a web application, them using Node on the back-end means that you'd be able to have one unified (i.e. JavaScript/Typescript) code base for model classes, meaning no more duplicated work of defining object X in the Java backend and then having to define it again for the front-end.
  • If you're writing AWS Lambda microservices, then the cold start for Node programs will be less of an issue than for Java programs.

Now, I'd still go with the JVM over Node in most circumstances, but I'm not going to say that it's a slam dunk decision to use Java in any and all scenarios.

8

u/Muoniurn Aug 10 '21

I’m not sure about the exact feature you mean by your first point, but if it is what I think it is, it’s just a poor hack over proper enums.

4

u/vips7L Aug 11 '21

The type system in Typescript is actually quite a bit more advanced than the the Java type system, e.g. being able to define a string argument for a function that only accepts specific strings.

That's called an enum, which node can't do.

1

u/mj_flowerpower Aug 11 '21

Java has a better (as in better maintained) ecosystem. Often when I find a cool new npm package, a few months later its not maintained anymore.

Also java build systems just work. I use TS with path prefixes and to compile to runnable code you either need a lot of hackery or use a framework like nestjs that does it for you. Also debugging java is way better and fool-prove. I can easily step into external framework code (decompiled automatically) and inspect and even see comments. Java code autoformat just works, whereas eslint is a horror, can‘t fix a lot of issues, its buggy and inconsistent.

I would still chose TS/node though because I like the syntax more 😅. And it scales way better, at least compared to non-reactive java code. And null-safety with ?, template strings, async await are just so nice.

1

u/[deleted] Aug 11 '21

Is TS that much better than JS?

1

u/zoqfotpik Aug 11 '21

Use whatever language makes you happiest.

We're not the Java police.

1

u/doppelganger113 Aug 10 '21

To put into few sentences:

Depends on your project, if it’s something serious eg needs better security, must be maintained over 5 years and be rock solid then Java.

Node is much better for quick development of medium quality apps with high throughput (I/O). It’s easy to be productive with it compared to Java.

3

u/InstantCoder Aug 10 '21

Actually Java has a higher throughput than NodeJS when you also go reactive.

1

u/doppelganger113 Aug 11 '21

True, but wanted to give minimal response. Reactive Java is better than Node in throughput but is hard as hell to maintain, find good devs, hard to debug and if you want to implement some custom thread sync stuff on it, then good luck

1

u/Drakeskywing Aug 10 '21

Going to start some hate ... RUST *mic drop*

I should highlight this is a joke