I've come across quite a few node projects lately that use the
async.waterfall method to execute a series of callbacks in a linear fashion. In some cases the
async.waterfall call is nested in a function body that has its own callback. I see code like this:
Notice that both the main
doSomething function and the functions in
async.waterfall have the same callback names, referenced as
In order to have distinctive callback names, I propose the following naming convention:
- Parent function callbacks are called
cb, those extra 6 characters won't hurt your fingers but will help people)
- Callbacks that are used with
nextin order to express linear (sync) execution.
Essentially my example above becomes the following:
The goal of the above is to indicate linear execution and to introduce a convention to distinguish between nested callbacks. In case there's an already existing convention, please leave a message as I'd like to know.
In order to get as many people on board with expressive conventions as possible and to make things easier for every single one of us in the whole community, please consider spreading the word.
I'm a Ruby/JS dev/trainer with a focus on quality. An ex-Londoner, @terracycle, @ubxd, @lastfm. Follow me at http://twitter.com/attilagyorffy