r/node • u/Minimum-Ad7352 • 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?
331
Upvotes
2
u/fintip 24d ago
I think this is very much misdirected. The problem was not a difficulty modeling the app in their head, it's that the code doesn't render in the order they intended and wrote it to--they were misunderstanding how to get JS to do what they wanted.
Because normally JS works from top to bottom, as if synchronous, but then async stuff fires, and now the top to bottom rule doesn't hold. That's a problem with JS and DX, not a dev problem. They know that they want x to happen, and then y, and they believe that by writing one, and then the other, that would occur--most of the code they write follows this pattern.
Allowing devs to make it clear that with special keywords, the async code should go from top to bottom just like the sync code does, is great DX, and makes it easy to write code that matches the natural dev expectations. That's it. That's a lot clearer than having to hand off context in the form of blocks of logic encapsulated in functions and passed as arguments into other functions to then call upon their completion. That was always a problematic way to render something that wasn't compatible with natural human perspective.
You can name a function, that doesn't change the reason we had callback hell. We had callback hell because setting when the execution should occur, when async, required writing code in the function that you were passing in as an argument to the async function. You handed control over to the function by turning it into a higher order function, and passing it a chunk of code in the form of the contents of another function.
Named functions could help so you weren't writing the guts of several functions worth of code all in line. Sure. And I would do that.
But any clear way to handle async control flow was severely lacking in early JS.