Is NodeJS Wrong?
31–40 of 47 posts
Re: Is NodeJS Wrong?
#32This is a bit annoying since if you want to make three async requests you have to write the following Well, beyond a style issue. You can unfold the events and make it a lot less "annoying". Consider, var cb1 = function() { } var cb2 = function() { req(cb1); } var cb3 = function() { req(cb2); } req(cb3); It's a lot cleaner and it looks like a state machine (and kind of looks like erlang/message passing).
Might I suggest you take a look at my preferred solution for this,
var cb1 = function(callback) {
callback();
}
var cb2 = function(callback) {
req(function() {
callback();
});
}
var cb3 = function(callback) {
req(function() {
callback();
});
}
sequence([
cb1,
cb2,
cb3
]);
The sequencer is a simple lib function you can find at https://github.com/michiel/sequencer-js or using 'npm install sequencer'Re: Is NodeJS Wrong?
#33It looks like the compute situation in Node.js can be helped with a server side web workers implementation .. with the workers doing no IO and only computes. Any thoughts?
Re: Is NodeJS Wrong?
#34Earlier quoted context omitted.
To me, it seems the real weakness of node.js is having to manage asynchronous control flow yourself, at all . It grows exponentially more ugly as the system increases in size. I really like continuation-passing-style as a technique (especially as a compiler IR), but doing that stuff by hand is so 70s . I got pretty far along writing a similar system in Lua (because, hey, event-driven systems are pretty nice), and unl…
Thanks for this, you've nailed the problem. I'm looking for a language that can do everything that Node.js does but also solves this control flow problem, but is also fast and has support for OpenCL and beefy math libraries. I don't find Erlang to be performant in this regard, so I'm looking at Scala but I'm constantly getting pissed.at.java.packages.and.conventions. I think it also suffers from the same problems as…
Here's an excerpt of a blog post (http://blog.mozilla.com/dherman/2011/01/30/proper-tail-calls...) from a research engineer at Mozilla Labs who works on the new ECMAScript standard:
>Having an officially guaranteed tail call mechanism
>makes it possible to compile control constructs like
>continuations, coroutines, threads, and actors. And,
>of course, it’s useful for compiling source languages
>with tail calls!
Of course, it is a long way to go until one is able to use these features. So, for now, you are better off to look somewhere else for your specific needs.Re: Is NodeJS Wrong?
#35Given any long-running task, there are two natural things to do: 1. Do something while the long-running task is running 2. Do something after the long-running task has completed Node.js' callback function convention simply makes it stupendously easy for you to write code for both cases, and leans towards making case (1) as natural as possible. Case (2) is naturally easy in Javascript (and even easier in Coffeescript)…
To me, it seems the real weakness of node.js is having to manage asynchronous control flow yourself, at all . It grows exponentially more ugly as the system increases in size. I really like continuation-passing-style as a technique (especially as a compiler IR), but doing that stuff by hand is so 70s . I got pretty far along writing a similar system in Lua (because, hey, event-driven systems are pretty nice), and unl…
I think there are people who did similar stuff for classic PC hardware, and already open-sourced their work; you might want to look at nmap, among others.
The external API is a superset of Luasocket's, so the event loop can remain completely transparent for users if they choose so. Proper coroutine support really rocks!
Re: Is NodeJS Wrong?
#36Earlier quoted context omitted.
To me, it seems the real weakness of node.js is having to manage asynchronous control flow yourself, at all . It grows exponentially more ugly as the system increases in size. I really like continuation-passing-style as a technique (especially as a compiler IR), but doing that stuff by hand is so 70s . I got pretty far along writing a similar system in Lua (because, hey, event-driven systems are pretty nice), and unl…
Thanks for this, you've nailed the problem. I'm looking for a language that can do everything that Node.js does but also solves this control flow problem, but is also fast and has support for OpenCL and beefy math libraries. I don't find Erlang to be performant in this regard, so I'm looking at Scala but I'm constantly getting pissed.at.java.packages.and.conventions. I think it also suffers from the same problems as…
Re: Is NodeJS Wrong?
#37Re: Is NodeJS Wrong?
#38It looks like the compute situation in Node.js can be helped with a server side web workers implementation .. with the workers doing no IO and only computes. Any thoughts?
Already exists. Do whatever you want in a webworker, using (very nearly exactly) the same API as you would in an HTML5 client: https://github.com/pgriess/node-webworker
Re: Is NodeJS Wrong?
#39Re: Is NodeJS Wrong?
#40Earlier quoted context omitted.
"Several commenters point out that long-running computations can be performed outside the main request thread without the server having to do anything special." Then why am I using Node.js? Any language has been able to do that for over a decade now, without the other hoops Node.js's style forces you to jump through. As evil and bad as shared-state multithreading truly is, this is a (or possibly "the") task it can ma…
I don't really understand your comment. No one's saying that IPC is unique to Node. The OP's criticism was: async i/o is fine, but what if you have some CPU-intensive work to do? Isn't it bad to let that block the whole server? Of course it is. OP's answer is a different server architecture; Nodians' answer is just forward that work to a different process and let Node keep doing the one thing it does well. Why use No…
For every major high-level language, there is at least one Node-like library, and sometimes more than one (Perl has POE, Event::Lib, based on my experience the raw glib wrapper isn't half bad albeit perhaps not the fastest, but you get good access to anything else based on glib, in fact Perl has so many that there's an Any::Event wrapper to remove your dependence on the underlying event library!). My point isn't that Node.js is bad. I actually don't think it is.
My point is that the hype is bad. It's wrong to think it's bringing anything unique to the table, because it simply isn't doing anything that has not be done literally dozens of times, except it's doing it in Javascript. If you want it done in Javascript instead of Python, more power to you. I'm particularly incensed by the idea that Node.js' approach to asynchronous is the only way to do it and the number of people it has produced who it has anti-educated into thinking Haskell and Erlang and all kinds of other languages can't possibly be asynchronous because you can't see the manually-chopped-up event handlers in the code. I'm not guessing. I've met these people online. You may know better, but a lot of people don't; whether or not it was intended the hype is actually lying to people about the state of the programming world, comparing itself to the world of 1995.
I am also trying to speed up the education cycle that all of those other dozens of attempts have been through in which manually-compiled event-based programming inevitably explodes into unmaintainable complexity, and none of the dynamic languages, including Javascript, have the necessary constructs to truly contain it. Some of the dynamic languages are even more powerful than today's Javascript, such as Python with its generators (though ECMAScript is supposed to be getting those, I don't know if any browser has them yet) and it's still not enough. The structure of event-based programming demands such an explosion. Been here, done this.
You can see it already starting to poke out from under the hype, if you're watching carefully. This is going to get worse, not better (because there isn't a solution, just a variety of hacks long since tried and found to only slightly improve things at significant complexity cost themselves), and I'm actually trying to do the community a favor by deflating the balloon so it doesn't pop so hard.
(If you know Haskell, and you look at the implicit type signatures being put on things like callbacks, it becomes easy to see the problem. The clearest place to see the problem is a function that takes a callback for something, until one day you need to pass in a callback that itself has to go do something that requires a callback and suddenly you've got a big problem. The usual callback in Node.js is actually just a relatively-pure function, they are not in IO, which is done behind the scene for you. Then when you need to do something else, you've got some real problems. Solvable, yes, but at a fairly significant complexity cost, partially because any given issue can be addressed but you can't really address all of them simultaneously (simplicity, exception correctness, dealing with control flow across callbacks, etc.). Every time you write a callback or choose where to break the function up into a callback you're actually laying down far more restrictions on the code than you can easily see, but I don't go to this explanation very often because by the time you can understand it it is also borderline obvious.)
What other alternatives are there? One, use Node.js with awareness of the issues. There are places where it is fine. I just would incredibly strongly anti-recommend it if you know you're going to be continuously developing whatever you're building in it, especially your core product, rather than writing "a proxy socket server for web sockets to conventional sockets" and being done at some point. The other alternative is to actually work in a language/runtime where you don't have to manually perform all this tedious work. There's a number of them coming out and one of them is probably going to go mainstream at some point; of the current lot Go would be my best guess. Google isn't pushing it, but it's still got Google's name on it, and I don't know of anything else right now with the equivalent name power. History suggests name power is necessary for a language to crack the mainstream in anything less than 15 years. It probably requires the least adaptation to a new style of the bunch, the other advantage it has from the mainstream point of view.