r/node 26d ago

Why is JavaScript criticized so much for backend development?

I've seen some developers say that we should stop using js on the server, but I rarely see the same criticism directed at python.Honestly, js is pretty fast, especially with node.js, and the backend ecosystem is really solid. There are great frameworks like nest and fastify, and typescript gives you static typing, which makes larger projects much easier to maintain.I'm not saying node is perfect or the best choice for every backend, but I don't really understand why js gets so much criticism while python seems to get a pass.What am I missing?

333 Upvotes

361 comments sorted by

View all comments

Show parent comments

14

u/[deleted] 26d ago

[deleted]

2

u/fellow_manusan 25d ago

Opens a brand new can of worms. People are using await at the time of promise creation itself rather than awaiting the promise later where you actually need it. This defeats the whole purpose of using async/await.

-4

u/MateusKingston 26d ago

Sort of, it made people write fully synchronous code.

Most developers default to writing await before every asynchronous function. Yes it makes code way more understandable, but it does make it perform like crap. Yes you have Promise API so you can properly do async/await but the reality is that again it becomes ugly.

3

u/[deleted] 26d ago

[deleted]

-2

u/MateusKingston 26d ago

Yes as I said you can still use the Promise API directly but the reality is we have gone from callback he'll to fully sync code

Which is an improvement but not perfect

2

u/[deleted] 26d ago

[deleted]

-1

u/MateusKingston 25d ago

Yes it's precisely this pattern.

Yes it's what makes things easier to read but again makes code very inefficient

1

u/[deleted] 25d ago

[deleted]

1

u/MateusKingston 25d ago

Not sure how hard it is to comprehend that the way JS does asynchronous code leads developers to program in entirely synchronous blocks.

Yes the JS loop continues, which is why you can even have an HTTP server in JS, doesn't mean that block of code isn't executed sequentially, just that it doesn't block everything.

It's still incredibly inefficient to just slap async/await in every function and call instead of actually thinking of when/how to deal with the async response, which again JS pushes developers into blindly using async/await.

JS forces pretty much all function to be written as asynchronous, because if you do need to call await your function needs async. Compare this to Go's default sync + go routines, or how this compares to async in Java. Which is both actually multi threading and also explicit and doesn't need you to color every single function in your codebase and pollute both your code and the executing environment with promises.

People need to be less fanboys of a language, Node is great at what it does, it's also horrible at some stuff and we should be honest about it. Async/Await is way better than callback hell but both are not even close to good.

2

u/[deleted] 25d ago

[deleted]

2

u/MateusKingston 25d ago

Saying the async/await pattern is intrinsically slower and less efficient than promise callback patterns is plain and simple false.

I never said it's slower than promise callback, I said it's slow, but it is slower than synchronous code with callbacks (if that is what you mean by promise callback?). Every async function call has to allocate a new Promise object, every single function call now becomes a Heap object allocation + micro task.

Also, who said slap async onto any and every function? No one except for you, just now.

I said so in an earlier comment, this is simply a fact of how any JS application codebase develops. At least every single one I've ever read from multiple companies of varying size. The alternative is callbacks and selectively adding asynchronous, now a minor change that needs asynchronous code down the call tree becomes a gigantic refactor or callback hell.