my approach to handle callback sallad? use the language features. just 
wrote down a script that would have a 7-10 callbacks nested. The problem 
with the callbacks is not the callback approach. it's simple and beautiful. 
the problem is naive and blind utilization of the closure scope. Just an 
example:

function lolAssert(){
  var forClojure = 'lol'
  require('child_process').exec( 'echo lol', function(err, stdout,stderr){
    require('assert').ok(~stdout.indexOf(forClojure))
  })
}

exec callback utilizes a clojure scope directly. in most cases you can 
easily avoid this:

function execCB(err, stdout,stderr){
    require('assert').ok(~stdout.indexOf( this ))
}

function lolAssert(){
  var forClojure = 'lol'
  require('child_process').exec('echo lol', execCB.bind(forClojure))
}

you can write it this way all way down. in most cases you even need the 
clojure scope/ this-binding. The script i wrote is nothing more that a 
number of small functions with no cb-nesting, no dependencies to 3rd party 
libs. this approach is perfectly usable for most of use cases, since the 
node callback pattern does not utilize this bindings. jQuery is different.

Am Montag, 12. November 2012 07:46:05 UTC+1 schrieb Mikeal Rogers:
>
> It's great that you have a strong opinion. Here's some numbers:
>
> Here's the number of modules that depend on async and Q.
>
> async: 975
> Q: 109
>
> Here are the numbers of downloads in the last month.
>
> async: 120,271
> Q: 33,242
>
>
> Some people clearly like promises, but the dominant pattern in node is not 
> promises, it's callbacks, with complex callback issues managed with async.
>
> Stating your opinion strongly does not make it a fact. This is your 
> preference, and many others, but not the majority.
>
> If you write a library, it better use callbacks if you want people to use 
> it. Using callbacks in your own application code is the path of least 
> resistance for using the majority of value in the node ecosystem. That's a 
> fact, there are numbers. It's not everyone's preference, but it's the most 
> popular by far.
>
> -Mikeal
>
> On Nov 11, 2012, at November 11, 20125:18 PM, Andy 
> <delva...@gmail.com<javascript:>> 
> wrote:
>
> To reply to my own very old thread after getting some solid experiences 
> with promises, the answers to my questions are:
>
> 1. *async* is a library that passes callbacks around. it's ugly and it 
> sucks.
>
> 2. a* promise *is just an object. Don't let anyone tell you differently, 
> they are just trying to confuse you. It's an object that has method names 
> that everyone's agreed on, like *then *and *done *which will magically 
> trigger your callbacks for you. With promises, you include *Q* and you 
> just pass around Q objects (called deferreds and promises). It's just that 
> everyone agreed that the promise object will have a *.then* method, which 
> you can call and your function jumps next in line onto the promise chain 
> magically.
>
> The libraries should *not *be used together. Once you get your head 
> around promises and use them in field you won't want to use anything else.
>
> If you are exposing an API, you should still take/call a callback. If 
> you're writing a database client you don't want to give the user a promise 
> and force them into your model. Just call their callback at the end of your 
> own, internal beautiful promise chain. It will be our terrible secret.
>
> Promises aren't perfect and can get strange when doing some complex 
> composition (lots of return statements to return promise chains), but they 
> make writing async code soooooo nice.
>
> -- 
> 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 nod...@googlegroups.com <javascript:>
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com <javascript:>
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
>

-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to