On Jan 26, 2014, at 9:24 AM, Filipe Deschamps <[email protected]> wrote:
> Guys, what do you think to prefix all callback functions with double 
> underscores? (or any other pattern that makes more sense to identify a 
> callback)
> 
> For example:
> 
>   model.save(data, __save);
>   
>   function __save(err, return) {
>     ...
>   }
> 
> I'm node/javascript newbie, but using a prefix for callback names is making a 
> huge different to scan the code (including using find features).
> 
> Are you guys using some name convention approach for callbacks? Or is this 
> just a newbie problem?
> 

Two things come to mind:

1. With NodeJS being highly async your code is going to be full of callbacks… 
functions (your own) that are callbacks will far exceed functions that are 
directly invoked. This means that the bulk of your function names are going to 
be __x. Which is fine,
I suppose, but it’s not clear how much differentiation is really obtained.

2. You may find that you are using lesser instances of separately defined named 
functions as callbacks, or even anonymous inline functions as callbacks, and 
instead using some technique like promises to organise your code. At which 
point, the code says: 
do_this().then(do_that).then(do_something_else).fail(oh_no).done(), and you may 
not think of do_that(), do_something_else(), oh_no() as callbacks.

2 cents,

        —ravi


P.S: Of course there is the standard conventions in Unix/C for the use of _ and 
__ prefixes, but I do not think your usage is in strong violation of those.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to