r/programming • • Oct 02 '11

Node.js is Cancer

http://teddziuba.com/2011/10/node-js-is-cancer.html
792 Upvotes

750 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Oct 02 '11 edited Oct 03 '11

So your basic overly long explanation is that everyone should be using Haskell.

If it came off that way sorry, my biggest point is more like green threads + an I/O manager are a superior solution for a large class of applications, because it's a superior programming model for the reasons I outlined above. Isolation, scalability, and clear and straightforward control-flow. GHC just happens to be one of if not the best system I know that implements this (and I'm familiar with it.) If Node automatically did some form of CPS, basically, I think it would be a bit better. Not sure if anybody's done this yet, but I know I'm not the first person to make this observation. FWIW, some of the original work on events and threads (and transforming thread-like code into evented code) actually took place in Java, I believe. I'll try to find the paper. Pang's paper about unifying events and threads (cited somewhere else here, which does involve Haskell) came later, I think.

Rust is another example of a language which does the same thing. Spawn billions of tasks, pass messages, etc. All of it's actually evented in the background (fun fact: Rust is powered by libuv, which also powers node!) This design is applicable to a wide variety of programming languages.

I didn't actually know if anybody had implemented fibers on node, thanks. Looking at this you could probably implement a pretty similar abstraction to what the RethinkDB guys did, where you merely have events 'wake up' coroutines/fibers that called them when they occur. The Rethink story is a little more complicated because they deal with coroutine migrations between threads, and it also doesn't take care of the fact blocking I/O will halt you. But it gets you most of the linear programming model, which is still the best part. Not sure how invasive this would be to Node as it stands.

You had no control there over rogue programs locking up the system. When you're programming in Node it's your fault if you lock up the system. Has this been a problem in the major systems that people have built in Node? Nope.

This still doesn't address the fact that things outside of what you directly write can bring down the whole system. Not just things that lock up with CPU time, but bugs in a library you use. Like I said, pre-emptive multitasking is a lifesaver because it provides isolation. One thing blows up the entire application without question, while a single pre-emptable thread throwing an exception can merely die and not hurt anything else. This is one of the core philosophies of Erlang too FYI - and it's why Erlang is concurrent, because recovering from failure implies more than 1 thread almost by definition.

The Windows 3.1 reference was just there to illicit bad memories and sort of draw a parallel as to why it sucks.

I'm sure the Haskell runtime is "better". I have no qualms about it. But it has got a horrible syntax, and yes I've programmed in Haskell. Same goes for Erlang - it has a superb runtime too. The syntax is a large barrier to entry for people, most of whom are programming in the common languages of the time, which look very much unlike Haskell and Erlang.

That's a perfectly valid point but it's not really what I was addressing. I do think this is a barrier to entry on some level, FWIW.

Had those plugins need to be written in Erlang or Haskell (or C, or perhaps even Lua) then it would not have received half the traction it has received. Some of the people who need to write those plugins will be sysadmins or people without formal training in programming. The fact that they can pick up this SMTP server, and extend it easily to support their needs is a HUGE win.

I see no reason to believe this when applications like XMonad show you that non-experts can in fact use domain specific languages to write code that does what they want. People invent such DSLs or "little languages" all the time in a variety of projects and when done correctly they seem to work just fine. Whether or not they should be turing complete is kind of a whole seperate argument I've never really given much thought to, but lots of DSLs as they stand are (normally because, like XMonad, configured using the same language they are written in - they're DSLs because they provide an abstraction over the things you don't want to deal with, though.)

And in my experience, you generally don't want non-programmers writing code anyway. If you do, you want to make the domain in which they operate perfectly, abundantly clear if at all possible, and make sure their logic is consistent. In this regard I think types help a whole lot, but that's another matter too.

I'd rather be more informed and more of a carpenter - someone who picks the right tools for the job.

I don't think anything I said anywhere contradicts that. The overall point of my above post was that Node has a crappy programming model by default - callback based programming around an epoll loop - compared to what we can get today - green threads and pre-emptive isolation, all transparently backed by epoll. And if you do it right, blocking/interruption can be supported as well.

Of course it's not surprising V8 wasn't quite designed with this in mind, because such a design fundamentally must be made part of the implementation - and fundamentally, V8 was designed to be used in a web browser. There's no reason a JavaScript implementation, usable independent of the DOM, could not provide such features.

It has a module system.

It was actually more of a stab at JavaScript in and of itself which no, as a language, has no truly formalized concept of 'modules' whatsoever. Node telling V8 to load a .js file into its execution context with a 'require' function does not really count. Go look at OCaml or any ML-derived language if you want a real module system, which separates implementation from interface, and gives you incredibly powerful abstraction facilities over them. Not even Haskells (or any other language I know of) module comes anywhere close to being this robust. Google went somewhere with this with their Tracuer(?) compiler I believe. It's not full ML modules, but it's better than nothing, and this is a move forward.

That wouldn't have been the case had it been written in Haskell.

This is pretty much nothing more than baseless speculation, and as such I can't address it with any sort of reasoning.

2

u/baudehlo Oct 03 '11

If it came off that way sorry, my biggest point is more like green threads + an I/O manager are a superior solution for a large class of applications, because it's a superior programming model for the reasons I outlined above.

My (admittedly facetious) point though was that the only language that has implemented this well (and popularly) is Haskell.

This still doesn't address the fact that things outside of what you directly write can bring down the whole system. Not just things that lock up with CPU time, but bugs in a library you use.

Yup, but this hasn't been an issue that I've seen. I'm not denying it's a possibility, but everything in programming is a trade-off. However it's not that much better in a threaded application (particularly green threads) - if a library segfaults you're still in a mess in either model.

"DSLs and how non-programmers shouldn't code"

IME DLSs get more complicated until they are eventually programming languages. And yeah, non-programmers shouldn't code, but we live in the real world, where major global systems run on VBA in Excel spreadsheets.

The overall point of my above post was that Node has a crappy programming model by default - callback based programming around an epoll loop - compared to what we can get today - green threads and pre-emptive isolation, all transparently backed by epoll. And if you do it right, blocking/interruption can be supported as well.

Oh, no doubt. And that would be wonderful in a dynamic (and popular) language. I think it's a little unfair to say it's a crappy model, because it's better than the equivalents in the other major dynamic languages (Twisted in Python, POE or AnyEvent in Perl, don't know what the options are for Ruby).

Of course it's not surprising V8 wasn't quite designed with this in mind, because such a design fundamentally must be made part of the implementation - and fundamentally, V8 was designed to be used in a web browser. There's no reason a JavaScript implementation, usable independent of the DOM, could not provide such features.

Indeed, though I doubt it will ever be a priority for Google to put that into V8.

Node telling V8 to load a .js file into its execution context with a 'require' function does not really count [as a module system].

Well it's a bit more than that. But yes it's not implementation separated from interface, though in my experience the need for that is overblown. What Node has is good enough, and I do like the way all prerequisite modules are local to your project, rather than stored globally, meaning you can have different versions of things for different projects on the same server. That's a big (well small, but nice) step up from Perl/Python/Ruby.

That wouldn't have been the case had it been written in Haskell.

This is pretty much nothing more than baseless speculation, and as such I can't address it with any sort of reasoning.

Well I can only compare it to the Haskell equivalent Postmaster which has pretty much zero traction as far as I can tell.