The Javascript
In my first post, I talked about the good things about developing with Node: responsiveness, flexibility, testing and the feel good feeling that developers love when having such a quick feedback loop.
My second post was about the downsides: memory leaks – and how to find them – and the infinite number of modules available, dependency management and module dependency. Some things that make me cry whenever I’m developing with it.
For this last part, a rather short post, I will just touch on Javascript.
When I joined the project I’m currently on I was fairly confident with my skill level. I knew how to create objects in Javascript, test using Mocha, knew a few extra frameworks to make my life easier and with the language in general. It’s amazing how much you don’t know what you don’t know.
Javascript has been around for so many years and been through so many changes over the years that a lot very smart people thought of different ways about doing the same thing. I love that. It simply shows how much flexibility the language has and how much it can evolve – take for example the latest trends in functional programming and how we now have JS libraries just for that.
One thing that caught my attention during this project was Promises, most specifically the A+ standard. Over the last two years I’ve played with them, experimented on a few pet projects but never really paid much attention to the difference they can actually make to your writing – not only in cleaning the famous Pyramid of Doom but also structuring your code and architecting your solution.
Throughout my journey I’ve learned how to test them, properly use them and enhance your flow with them. A great post written by Nolan Lawson helped me understand them better and not abuse them – as with anything, there’s space for everything.
Also learned that, in Node specifically, you want to use properly written library – like Q – instead of Node’s own Promise. The implementation in Node is different and you really can use some extra features present in Q.
After four months I’m safe to say: I would not go back to callback hell unless there was no alternative.
But Promises are not the only thing. When developing with Javascript you have to make space for the quirkiness of the language. Things like:
if (a === b) { ... }
Or even…
(function() {
...
})();
Or even more…
(function(num) {
...
}).apply(window, [1])
Some people hate it, some people don’t care – I think it’s a bit too much to say that some people love it?
Regardless, that’s what make Javascript… well, Javascript. And those are language features that may or may not have helped move Javascript to the top 10 of most used languages these days. It can be run anywhere right now and is being used to communicate with low level hardware to web development. It must be doing something right.
And with ES6 just around the corner – ES6 was approved by ECMA International last week – things can only get better. There’s a bunch of good stuff being introduced in the language that will divide opinions everywhere but it’s the next logical step to make a good language great.
To know more about ES6 – and practice a bit – check this ES6 Katas.
Thanks for reading, until next time!
Source of blog: http://tarciosaraiva.com/2015/06/27/nodejs-the-good-the-bad-and-the-javascript-part-3/