Don't write spaghetti code in server side JavaScript

Sever Side JavaScript (especially Node.js) is a hot topic right now, but we are still figuring out what good SSJS code looks like. It isn't enough that we can write JavaScript on the server, or even that it is well written JavaScript. It's essential that we write maintainable JavaScript for the server environment. This talk will examine different coding styles for event driven, non-blocking SSJS and which styles are most successful.

We'll take a look at strategies that other languages and frameworks with similar attributes such as Clojure, Erlang, Python/Twisted and Ruby/Event Machine use. From these languages we'll take a look what has worked well and what hasn't. We'll explore how these models can apply to JavaScript to create patterns that can be used to make code more maintainable.

Since JavaScript is already an event driven language there is already a lot of support for events, and developers are used to developing code with the event driven browser. However, how we use these features on the server with it's additional freedom can either help or harm the long term use of our code. One of the obvious code defects created by poor use of the evented model in JavaScript is Pyramids. Pyramids are huge chains of nested, dependant anonymous callbacks piled one on top of another until you end up with a pyramid of code, left to right. Pyramids are one of the first, obvious, mistakes people tend to make when beginning SSJS. We'll also discuss some of the less obvious ones and explore ways of avoiding them.