89 points · by shawndumas · 16y ago · 34 comments
I like async, and I like node. However, for plain jane dynamic web apps, with no real time needs, I see it as being more of pain than using Ruby (or Python, or whatever).
Why? JS syntax kinda sucks for dealing with day to day business logic. Ruby is just more clear and easier to work with.
I think using node.js by default is bad design. It should be isolated to the cases where you need it.
As a JavaScript developer working with node.js (and client side scripts too, of course), I’d like to recommend a couple of related things:
Joose3 — an object system for JavaScript which allows truly classful programming; use it to implement all sorts of meta-programming magic with ease: http://joose.it/ http://openjsan.org/doc/s/sa/samuraijack/Joose/3.011/lib/Joo...
JooseX.CPS — a continuation-passing-style "trait" for Joose classes which helps prevent your asynchronous code from turning into "callback spaghetti": http://joose.it/blog/2010/08/02/asynchronous-aka-non-blockin... http://openjsan.org/doc/s/sa/samuraijack/JooseX/CPS/0.11/lib...
Joose is open source, works with both node.js and in browsers, and there are various ways to install and leverage its libraries, e.g. npm: http://github.com/isaacs/npm
This isn’t an advertisement. I started exploring node.js in early 2010, and my "discovering" Joose was a real boon as I was looking to do some complicated things that seemed daunting when trying to express the concepts in terms of prototypal inheritance.
Not everyone finds it attractive, but I’m always happy to spread the word in hopes that Joose can make someone else’s life and programming projects a little less stressful, which is what it's done for me.
task :default => [:test]
task :test do
ruby "test/unittest.rb"
end
Let's see what that could look like in CoffeeScript, assuming a similar library: task default: ['test']
task 'test', ->
ruby 'test/unittest.rb'
Pretty nice. Running that through the CoffeeScript compiler produces this JavaScript: task({
"default": ['test']
});
task('test', function() {
return ruby('test/unittest.rb');
});This is not necessarily a good thing. Sometimes you need to write a piece of code that executes sequentially. Having the ability to do that if you need to is a good thing. Sometimes it can be unnatural and unwieldy to split a block of functionality up into a set of callback functions.
Another thing is, when you go async, you're essentially giving up on using the language runtime's stack for most purposes. With that, you lose some useful functionality (useful stack traces, exceptions bubbling up).
twisted solves networking problems of all types really well, but (as Paul mentions in his post), most libraries for python are written assuming they have the entire interpreter to themselves for as long as they want (which in the naïve case, turns it into tornado, but it at least has facilities for running async tasks in other threads or processes).
node.js does as well, but it's developing a very rich library very fast. Certain things are harder to deal with (personally, I think twisted got async error handling right and most everyone else hasn't got there yet), but people think they understand javascript better than they think they can understand twisted.
Twisted has support for many network protocols while Tornado only has support for HTTP (client and server). If you are doing something other than HTTP, than Twisted might be the better choice.
One advantage to using something like Node.js, however, is language homogeneity: having all your browser client-side code and server-side code in 1 programming language. While it's good to use The Right Tool For The Job there's also a benefit to having the simplest solution possible, with the least amount of moving parts, and requiring the least amount of tech knowledge (esp languages) to deliver that solution. While I prefer Python to JavaScript, if we never get to a world where Python is built-in to every browser there is some attraction to moving in the other direction. "If you can't beat 'em, join 'em."
I thought there was fairly universal agreement that while javascript has many strengths, its syntax was not one of them.
Doesn't solve that problem (which is really, really hard) but it's a very interesting step.
That being said, you could hack something together with a very optimistic approach using knockout.js and socket.io (to gracefully degrade if websockets arent available.)