Javascript, Operating System of the Internet

First off, before you do anything else, go read this nice article on revisiting Javascript.

Somewhere along the way, perhaps with the original introduction of jQuery, or maybe with the introduction of Ajax with Google Maps, the hilariously misnamed Javascript went from being the curiosity of embedded browser languages hardly touched to the operating system of the Internet.  What was once a language for doing bad front end validation on forms has become a front end language, a middleware language, and a backend language.*  Coupled with its native communication format, JSON, it's become the thing that holds all the stuff together.

Node.js is the new hotness.  Its core architecture based on libevent gives it the fascinating illusion of being single threaded asynchronous.**  With tuning and filling up a CPU with processes, node can certainly look like it is asynchronous and phenomenally fast -- the Internet is filling rapidly with people amazed that node.js is faster than Java.  This is an illusion -- for reasons when I start digging into libevent's magic, it turns out that having a static number of threads all sitting and waiting for a query to finish on a database is never going to be as fast as an evented library doing just-in-time things as interrupts come off the operating system to user space.  Doing something is always faster than a NOP even if Java is fundamentally faster at its core that Javascript and always will be.  The illusion has more to do with computer architecture and pipeline construction and some operating system fundamentals but no one really cares -- all they care about is that node is fast, node is quick to get up and running, node is easy, and now, for the first time, from AJAX calls down to the database, it's all talking JSON in Javascript all the way down.

This is remarkable.  It's actually........................ elegant.

My core issue with Node.JS, and Javascript in particular, is that, at the end of the day, you're still programming in Javascript.  Slap all the fancy libraries to neaten it up all you want, install express.js, install backbone.js, anything you want and it is still Javascript.  For reasons I could never put my finger on, Javascript, in whatever form, turns into Javascript at the end of the day, and it's a mess of bad habits, weird variable names, curly braces exploding, closures that make no sense, and madness.  There is no neatening of Javascript.  There is no saving it from itself.  The only thing to do is to push the pile around into a slightly neater pile and hope for understanding at the end of the day.  Oh yeah you can whip out coffeescript -- I tried that -- and even the coffeescript turned into Javascript before it was compiled.  

It's like turtles all the way down but with Javascript.

It's like turtles all the way down but with Javascript.

I don't know what it is about the language.  If it's some psychic beam it shoots out of the monitor that makes a perfectly good programmers turn into a crappy one.  Maybe it is callback hell. But even with naming and promises... well, it'll get there.

So when I thought about this project I got right to the answer and said, well, I'll write it in node.js on the backend with a javascript MVC2 web framework like angular.js on the front end and just go to town.  Problem solved, toolchain chosen, let's get the VIM plugins installed.  But that's no fun.  

I end this little diversion on javascript and node in particular on mentioning Yertle the Turtle.  When I look at the whole Javascript universe I think of this:  

So Yertle the turtle king
Lifted his hand
And Yertle the
turtle king
Lifted his hand
He ordered all the turtles
Onto one
another's back
He piled them high
Into a ten turtle stack

The future Internet stack looks alot like this.

  • The fancy term for this is "full stack language" for a "full stack engineer."
  • It's not truly asynchronous.  Even libevent has a global interpreter lock.