As the Backboard experience gets richer and richer, more of it moves to the browser from the server. It’s a win-win-win: Increo gets less load on our servers, you get better response time on your computer, and the team gets to write code in the awesome language that is JavaScript.
As such, we’ve spent a long time working on making it as consistent and manageable as possible. With apologies to Wil Shipley, some basic suggestions for maximum JavaScript happiness follow.
Use a JavaScript framework
If you’re still writing JavaScript without relying on one of the myriad open-source DOM-savvy Ajax frameworks, you’re wasting your time and effort. You have lots of choices:
Backboard is built on the (large and supple) shoulders of Prototype, but we hear they’re all pretty good.
Don’t host your own copy, though: use Google’s hosted version. That way, your whole app loads faster when your users don’t have to even download the JavaScript file because it’s already in their caches.
Use namespaces, or the next best thing
Sure, JavaScript is technically a language with a flat namespace, but since it’s prototype-based instead of class-based, you can just use objects. Instead of this:
function my_namespacer_hopefully_nobody_collides_runRequest(arg1, arg2) {
return "Haha! This function has a really long name!";
}
you can have a simple “namespace” object of your own:
var MyStuff = MyStuff ? MyStuff : {
runRequest: function (arg1, arg2) {
return "So much better!";
}
}
You may think you’re organized enough to keep everything straight, but once you start pulling in libraries and other people’s code, you’re going to be in a world of hurt. After all, you don’t want your next big app looking like PHP.
Employ some automated syntax checking
And by “some automated syntax checking”, I mean JSLint. We use the following set of options for our source code:

The face of Backboard (that is, the JavaScript that runs in the browser) is almost 1,300 lines of JavaScript. Running it through JSLint helps prevent dumb errors and bugs and it keeps all of us honest. Having an easy way to enforce coding guidelines makes it easier for everybody to work together and make your quality consistent.
Let your server deal with download efficiency
Shipley sez “Tiny code is always best”, but I’m pretty sure what he means is you should express yourself briefly, without wasting code writing extra methods you don’t need or class hierarchies just because you can.
Repeat after me: whitespace is okay. So are comments.
You’re better off writing beautiful, well-documented, understandable code and having your application compress it with things like JSMin or the YUI Compressor and mod_deflate.
Those 1,300 lines of JavaScript in Backboard started at 46 kilobytes; after running them through JSMin and mod_deflate, they’re 8.2 kilobytes. Having it set up to run automatically is an order of magnitude more worthwhile than any effort to minimize code size.
All of this leads us ever closer to JavaScript happiness. And, of course, that’s the whole goal, right?