4 ms·
Drinking the Node.js Kool-Aid
- mkramlich 16y agoNode.js is one of the most promising sounding projects I've seen in the last year in terms of something I may actually use in production code. JavaScript's agile syntax combined with ubiquity thanks to web browsers make it one of the few languages that would make switching to it bearable for, say, a Pythonista like me. And Node.js may be the final straw that unleashes it on the server-side.
- weixiyen 16y agoCurious though, if you are a Pythonista, why not use something like gevent or tornado?
- dlsspy 16y agotornado solves one very specific problem that friendfeed had. It's being used for other problems, but it solves them less well than, say, twisted. 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.
- frognibble 16y agoTornado solves the problem of building web frontends, particularly those with comet features. This problem is not specific to FriendFeed. A number of other services use Tornado including Brizzly, Quora and Hipmunk. 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.
- Locke1689 16y agoThe author mentions how he switched from using Twisted to Node.js. I would be very interested in hearing more about the advantages and disadvantages of this as I am building a service in Python right now that I am using Twisted for. I don't really know anything about Node.js but I have been hearing a lot about it. A couple hangups for me are that 1) I'm not a huge fan of Javascript itself and 2) I'd really rather not mix Python and Javascript together. Note that my app doesn't currently use HTTP and maybe that plays a role in Node vs Twisted.
- dlsspy 16y agoI argue that twisted is better for most practical uses of comet. Tornado mastered only the "have lots of suspended connections" thing. Many of the examples involve blocking for processing one of those connections. What's the point of having 20k connections terminated on an http comet connection if you completely block the entire event loop to service a single one while you make another network connection (e.g. memcached, mysql, etc...). In this regard, most real life comet apps are doing more than http. To be fair, tornado did ship with a yet another python http client, so you can at least use it with a database that speaks http without blocking, though without chainable deferreds, it's hard to do the exact right continuations required to chain these events together without locking the event loop.
- frognibble 16y agoThe Tornado philosophy is to use blocking for fast operations and async for the occasional long operation. Tornado applications compensate for blocking by running several instances of the application. Twisted is theoretically better than Tornado because everything is async in Twisted, but Tornado is more practical because it's easier to write straight-line code than chains of callbacks. The cost of Tornado is that you need more memory on the frontend because you run more instances of the application. In my previous comment, I listed some real life comet applications that use Tornado. What real life comet applications use Twisted?
- dlsspy 16y ago
- mkramlich 16y agoThose have attractive qualities too, you're right. 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."
- thomaspaine 16y agoI never understood this argument. Client side javascript and server side javascript aren't really the same at all, it's not like you can re-use your client side javascript on the server. The only benefit I see is that you don't have to context switch between python and javascript, but the only time I can remember this affecting me is when I forget to type semi-colons.
- aaronblohowiak 16y ago"it's not like you can re-use your client side javascript on the server". The other is more appealing. The wins for client/server code share are for things like field validations and templates.
- Encosia 16y agoThat's not always true. Templating is a perfect case for reusing code on both sides of the connection. In the optimal scenario, the browser can render a template based on requests for JSON data. However, if the client doesn't support JavaScript, the same template can be rendered on the server-side and fed to the browser traditionally. Great for accessibility and SEO. Input validation is another situation that's a great candidate for shared code. Another nice benefit is that server-side JavaScript brings an assortment of mature DOM selection/manipulation engines with it. I believe there was an example of using jQuery on the server-side with node.js posted here recently. Jaxer[0], which was ahead of its time, had a nice approach to sharing client/server logic with its runat="both". It's a shame that project never got much traction. [0] http://www.jaxer.org/ http://www.jaxer.org/
- percept 16y agoI see it as a kind of Switzerland that will draw from all camps in a way that other languages/frameworks haven't.
- allertonm 16y agoWhat on earth constitutes an "agile syntax"? I thought there was fairly universal agreement that while javascript has many strengths, its syntax was not one of them.
- andrewvc 16y agoSince we're talking about node... 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.
- FlemishBeeCycle 16y agoIf you find the syntax to be a problem - you may find CoffeeScript (http://coffeescript.org/ http://coffeescript.org/) interesting. It emphasizes the good parts of JavaScript while minimizing the warts, all wrapped up in very nice syntax.
- jashkenas 16y agoHere's a fun example. Matz (creator of Ruby) contributed a chapter to Beautiful Code (the O'Reilly book). In it, he uses this example of a Rake task as his example of a beautiful piece of Ruby: 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'); });
- rbxbx 16y agohttp://coffeescript-theparts.heroku.com/ http://coffeescript-theparts.heroku.com/ this could be of interest, although the actual coffeescript site is better/great...
- weixiyen 16y agoI don't think syntax is really that much of an issue. The fact is if you might expand to real-time apps later on, you'll have to write new abstractions all over again for stuff like fetching data, whereas if you started with something like node.js, you wouldn't. It's simply a matter of if you feel it's worth it or not, and it's really case-by-case.
- bostonvaulter2 16y agoSo it is possible to write an entire webapp in Node.js? I think I'll try it out on my next project since I don't have experience in any web frameworks. I wonder if Node.js has any Postgres bindings.
- rpmcb 16y agoBy Dahl himself, actually. http://github.com/ry/node_postgres http://github.com/ry/node_postgres
- flipp 16y agoYes and yes.
- Grantmd 16y agohttp://expressjs.com/ http://expressjs.com/ is a good web framework for node, if you can get over the fact that their docs all assume that you know Ruby and have used the popular templating engines in it.
- equark 16y agoWhile node.js has some appealing characteristics it doesn't seem to solve the main problem with realtime web apps -- coordination between the multiple client side view states and the server side state. It's easy enough to hack together communication between these two layers but it always feels a bit half baked. Something like etherpad should be the new hello world app.
- aaronblohowiak 16y agoGroupware is an extraordinarily difficult problemin this respect, especially if you want to handle the rare edge cases. The problem with maintaining multiple client side view states to be the same has a great deal of intrinsic complexity due to the very weak guarantees provided by network communication (if you want any kind of responsiveness whatsoever.)
- equark 16y agoTrue, but I suspect there is a lot that could be done by baking something like the feedsync protocol together with knockout.js style view binding, node.js and a websocket connection.
- aaronblohowiak 16y agoThe problem with feedsync and trying to serialize knockout.js to disconnected clients is conflict handling. Secondly, you have to worry about potentially divergent states if messages are lost in-transit (depending how robust your needs are.) 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.)
- jchrisa 16y agoI tend to solve the problem of showing the same state to all users with the CouchDB _changes feed. It fits the groupware problem like a glove. Here's just one example app: http://couchapp.org/focus/_design/focus/index.html http://couchapp.org/focus/_design/focus/index.html
- enneff 16y ago"Everything is Async: Because the base environment has been built essentially from scratch, everything is asynchronous. This means there is no ‘defer to thread’ like in Twisted Python; You just can’t make blocking code." 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.
- mjw 16y agoYep. Your code ends up looking like the output of a continuation-passing transform, with every kind of sequential composition involving nested callbacks. It feels quite low-level and clunky and is one of the things I like least about writing Javascript on the browser. 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).
- Andi 16y agoUse Step, man