
I very recently concluded, that as everything was very suboptimal with the Django, and especially the MongoDB usage combo, I should go for something else. This was not a very hard decision, as thankfully most of my code from my Django project was client-side JavaScript. I could turn to newer and hipper python frameworks like Twisted to encroach upon some of the newer web frameworks' performance, but with no asynchronous Python drivers for MongoDB, it seems I would have to learn yet another scripting language - or return to PHP.
Turns out there's another way now. JavaScript.
The reason for why DOM scripting is so good with JavaScript, is that it's completely event driven and asynchronous. One thread running from top to bottom, simply attaching callbacks to events, and with a sensible hierarchy of events so that events
bubble up, i.e. a click on a ul > li > h1 will trigger the most specific match first, then eventually any click listeners on li, ul, and body unless cancelled in the innermost matches.
NodeJS maintains exactly this event loop in its JavaScript interface, but uses it to actually implements a socket thread pool underneath (in C), for you to build a web server upon. It generates a lot of buzz these days, and with no thread per connection overhead from Apache, it gives you a remarkably simple way to create a web page with amazing performance. I mean, it's not quite C or Erlang like yet, but for an easy to write scripting language, it is astonishing. Take it from me, who am now actually coding multi-threaded C++ professionally (albeit not very well); this shit is hard, very error-prone, and very slowly progressing. It should only be done if you have plenty of time to do it, or you are an expert. Thankfully, I have plenty of time for it, with concentration inducing
Grooveshark playing in the background.
This puts me in a peculiar situation. Everything I do in my own time, is done in JavaScript. NodeJS runs Google's highly efficient V8 JavaScript engine, MongoDB runs Firefox's SpiderMonkey engine, and the result is that to me, everything runs smoothly. The
native MongoDB drivers runs problem-free, asynchronously, with the same syntax as the mongo shell. Most importantly, however, the rise of JavaScript compatibility in browsers is now so high that developers can justify complete reliance on it. Goodbye to the days of replicating validation and rendering twice. Better browser support plus universal JavaScript allows for code reuse!
My server code is, at the moment, shorter than what I had in Django, but already I have more functionality. Clearly, the challenges lie elsewhere. NodeJS is easy, and brilliant. That said, perhaps the most useful thing I have learnt recently came as a result of this
interactive JavaScript tutorial. Don't miss out.
*waves goodbye to Apache*