SandorHQ — Asynchronous Discipline
One of the most interesting aspect of Node.js is that it’s asynchronous, therefore it has the potential to cause as much frustration and damage that balance out all what could be gain by its speed worthy of the Millennium Falcon.
Of course, Node.js is a relatively young programming environment, still very much in the making, and this also applies to the frameworks available for it. For SandorHQ Express seemed appropriate, even though its creators are already busy working on their next bleeding edge marvel, Koa.js.
Initially I had planned on using MongoDB for storing dynamic data via Mongoose, but I didn’t like a few things about this ORM, for example that it’s not validating the model on
update, only when directly executing its
save method. I’m sure that there are some use cases when the asynchronous nature makes certain validations impossible, but an API should not ever be counter-intuitive. Besides, storing my content in flat files allowed me to simplify deployment to a mere
git pull command that refreshes everything from my private GitHub repository.
Christmas Tree of Hell
Yes, Node.js likes callbacks, and Express is not an exception either. The successor of Express, Koa.js uses generators of the new ES6 standard to avoid having to use this awkward, difficult to read and write albeit not illogical approach, but as it has still has not matured to have a stable API I haven’t chosen this technology.
Well, Node.js definitely requires a different mindset than synchronous languages, and should not be used as a direct replacement, just because it’s “asynchronously fast.” In most cases properly configured caching layers can guarantee speed and can prevent some multidimensional, holographic headaches.
Tabs or Spaces? Both!
Express lets you use any kind of view rendering engine, and I’ve chosen Jade, which slightly reminds me of regular expressions – they’re easier to write than understood at a quick glance. It also uses white space for defining structure, much like Python (more on this later), which in my mind nicely separates executable code from the view templates.
Regarding the religious question of whether to use tabs or spaces for code formatting, I say tabs for indenting, spaces for aligning, and it should be a personal setting just how much character a tab should represent. 2 or 4 is fine for me.