Wednesday, August 6, 2014

Why should you use node and avoid compatibility breaking "improvements"

There is a lot of hate this days against Node, I have a feeling that vocal minority is skewing the signal to noise ratio so I want to write few paragraphs why I'm using node and why it might be a good fit for your next web application.


Reasons to use it:


The platform works out of the box without tweaking. I've installed it on several different versions of the supported platforms (Win,Linux, Mac) It always worked without a hitch. This might seem trivial to most mainstream programmers but many niche languages require shovel and lantern before they're usable.

JavaScript supports first order functions, which coupled with lodash/underscore offer an usable option for writing functional code as your needs and taste fits. 

Node has at least two quality IDEs that work out of the box without tweaking, which I've used and could personally vouch for: 
I'm a visual learner I must see the project structure with syntax highlighting and be able to run the code & set breakpoints from the IDE to be productive. Editor mode won't gonna cut it, unpolished obscure plugin written by enthusiasts in their spare time and only tested under Gentoo compiled with specific CFLAGS is definitely not a viable replacement.

Full stack development is much easier by enabling writing the client code, server code & database code in JavaScript.  Lack of context switching and writing glue code enables staying focused on  the problem. Partial reuse of the code on the both ends represents a nice option.  

Huge very supportive community that makes a living by writing web applications and is ready to share their real world experience. Who would you rather have with you as the guide in the desert ? Someone who wrote a book about it or someone who lives there.

And last but actually the most important is the npm ecosystem.  As of end of July 2014 npm surpassed maven thus becoming the leader in the number of available repositories:
Source http://www.modulecounts.com/ 06.08.2014

Node has a plethora of production ready and battle tested libraries offering you the luxury of concentrating on your application. Whatever your external dependencies are there is a good chance that official module already exists. And I personally prefer writing my code instead of wrestling with half baked driver for some niche database I need to use.


Use the de facto standards:

Node doesn't have a committee nor a dictator to enforce its standards but streams and error first callback pattern emerged as tacit agreement judging by number of libraries written.
It's a decision being made and whether vocal minority like it or not, complaining about it has the same effect like complaining about significant white space in python or parenthesis in lisp.

In true Darwinian contest the fallowing libraries emerged as de facto standard in the platform:
- Lodash / Underscore javascript utilities
- Async asynchronous programming
-Express minimalist web framework
-mongoose mongodb object modelling

Start your projects using the standard libraries and switch to alternatives only if you really, really  need something very specific and you are willing to pay the price of breaking the compatibility. 

Mature communities don't usually tolerate forks in compatibility, this is true across many platforms and the less academic a community is the less tolerant it will be of ideas of for ideas sake and the node community is anything but academic- Mikael

Beside the de facto standards there are many libraries where the jury is still out:
- Templating  - I  use Jade  but Handlebars is very popular
- Testing - I like Mocha + Chai combination but there is also intern 
- CSS - The usual suspects Stylus, SASS & Less
- Real time web frameworks- I use socketstream but development has been lacking lately. The gorilla in the room is meteor which got 11 M$ in funding so they might become THE standard.  I avoid it mostly because its not officially supported on windows and their walled garden approach with meteorite makes me little bit uneasy. Sails looks as an interesting approach and is actively maintained.

Avoid languages that compile to JavaScript:


My dislike for the languages who treat  JavaScript as glorified assembly has nothing to do with the quality of those languages per se and everything with fragmentation that arises from it. When someone writes code in those "improved" languages my initial reaction is to avoid it, and I have a feeling that reaction is almost universal. We all have our favorite syntax or pet feature from other languages JavaScript serves as a language that we all understand without deciphering the flavor of the week. 

If you want to write code running in the browser JavaScript is the only choice.You could either write it yourself or use some language/technology that compiles to it. And no matter how many benefits the authors of those "improvements" claim  whenever you start writing something non trivial you'll get into nasty problems and all your high level savings will be wiped out by law of  leaky abstraction. All the tooling built in the browser to debug your source code is built with JavaScript is mind.


In the end use whatever tool makes you most productive and leads you to best results, in many cases node is the right tool.





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.