Why I think Node.JS is a terrible platform

Feb 23, 2017 13:32


Статті на сайті (http://www.tuicool.com/articles/hit/IfqQ7z) автора вже немає тому копіюю її текст з http://www.tuicool.com/articles/IfqQ7z

Note: I’ve made some edits about half way through the post

Node.JS is a terrible platform. It’s terribleness stems from a very simple aspect of it, and this aspect happens to be central to how it works: callback-based I/O

I think everyone knows this by now. This way of writing code is terrible.

A few days ago I realized something. After working with Go for a few weeks, I’ve come to like it. Yes, it’s less dynamic than python, and some tasks require more work to get things done (essentially some more boilerplate). There’s much less “magic” available. For instance, there’s no way in Go to provide context-locals as Flask does.

This explicitness in code makes it easier to read code. When there’s less magic, you don’t have to keep as much in your head as you would have to while reading python code.

We can say that there’s some sort of a tradeoff here, you trade some of the expressiveness in exchange for speed and maintainability and peace of mind.

Compare this tradeoff to the one you have to make when you switch from Python to Node.JS

You lose expressiveness, you lose maintainability, you lose peace of mind, and you get speed.

I seriously question whether the “speed” you get with Node.JS is worthwhile, given that you lose both ease of development and ease of maintenance.

I wasted a lot of time trying to learn node and do something useful with it (other than a dumb file server), but couldn’t. I just didn’t really know where to begin.

Usually I’d judge technology based on its own qualities. Is it nice to work with? Does it help me be productive? Is it well documented? Are there resources for help?

Node.JS fails that test. It didn’t make me productive at all. The APIs might have been documented, but it wasn’t clear how to piece things together to make something useful. The async-style of programming is almost entirely inaccessible to my brain. Certainly not a fun way to write programs.

Why did I waste my time with it? Hype (and Hacker News).

I saw people on HN say good things about Node.JS, and I thought: these people are smart and know what they’re talking about, so it must be a good platform.

Unfortunately, it took me several months to realize what a terrible platform it was. I wasn’t really able to produce anything useful on the backend beyond a simple server that serves jade templates and stylus stylesheets.

As soon as I wanted to write any non-trivial code to read stuff from a database and do something with it, I got stumped - I didn’t know how to proceed. I could write some code, but it would turn out very ugly. I couldn’t write code that was pleasing to read (and it certainly wasn’t pleasant to write).

The thing with the node.js ecosystem is that there’s always 3 or more libraries for everything, so when your experience with one library turns out to be not so good, you don’t immediately blame node.js - you blame the library - and you go looking for another one.

I was starting to seriously question my programming abilities!

Of course, some readers might say: we were productive with Node.JS, so this is just you being incompetent.

Alright, I will accept that. I may be stupid in some way that prevents me from being productive using Node.JS, but my point about the tradeoffs still stands: you have to sacrifice both readability and writability with node.js in order to reap the promised “scalability”. This is a terrible, terrible tradeoff.

You can get decent enough scalability even with Python. You have
gevent
, a coroutine based networking library/server. This means that blocking IO is not a problem. The only remaining problem is the python interpreter, which can easily be mitigated by distributing the load across multiple servers (which you will end up doing anyway if you really want to scale).

So what exactly is your excuse for choosing Node.JS as your backend platform?

The only thing that Node.js can do which Python can’t is websockets. Actually I’m not really sure if python can’t do it, some googling suggests that
maybe it can
, after all.

Of course,
Go can do websockets
just fine (
go get code.google.com/p/go.net/websocket
), but that’s besides the point.

Even if we suppose, for argument’s sake, that python can’t do websockets; that’s still not a good reason to write your web app in node.js. You can do the websockets in node.js and the rest of your app in python, as illustrated by
this example
from the Flask project. Yes, this setup (combining python and node) might be a bit convoluted, but it’s still better than actually writing your entire web app in node.js.

javascript, програмування, node.js

Previous post Next post
Up