10 ms·
One of "coolest" things about Javascript (that persuades many to try Node) is that it has a non-blocking control-flow. But if you are coming to Node from a PHP
by spenvo 13y ago
One of "coolest" things about Javascript (that persuades many to try Node) is that it has a non-blocking control-flow. But if you are coming to Node from a PHP/Ruby background, you might lament the default synchronicity of PHP. For example, you query your database in PHP, you can rest assured that your program doesn't keep running without the DB result. In Node, you either 1.) descend into "callback hell" or 2.) use some sort of Async module [ https://github.com/caolan/async https://github.com/caolan/async ]. I personally love Node but would say 'Expect to learn new patterns' to anyone making a transition to it.
- gridmaths 13y agoThis is probably the most common hiccup in getting started with node. I think this is the reason node.js is either loved or hated : if you get over this activation energy hump, you love it, if not you hate node.. to a first order approximation. Basically, to get over this hump, you need a small piece of code which can handle a sequence of tasks in order : I wrote serialq npm to a minimal implementation of this, and there are much better ones for production use. So, once you have a sequential task Queue, you can use it to program in a more procedural way to get started with your early apps.. then you will use it only for a few edge cases like startup initialization, and you will be comfortable with callback-heaven :] Callback-heaven is not a new idea.. you may not have heard of CICS COBOL system.. its an ancient mainframe terminal client-server app framework system with some of the same ideas. As a side note, be aware you don't need to have many levels of indentation in your code.. its a bad symptom in node javascript or in any other language. Just as novice programmers can make deeply indented code in Pascal or C.. you can do it in your node.js program. Just realize its bad style and think of nicer ways to structure it. Async does not imply deep indenting.
- spenvo 13y ago*edit --> "lament not having"