Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-09-01 Thread Bryan Donovan
Right, I get that. On Sep 1, 2013, at 8:59 AM, dhruvbird dhruvb...@gmail.com wrote: @Bryan: Be careful when using the EventEmitter like pattern because: var e = new ObjectDerivingFromEventEmitter() e.makeRequest(request_parameters); e.on('error', function() { }); Now, if makeRequest()

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Juraj Kirchheim
On Thu, Aug 29, 2013 at 3:16 AM, Isaac Schlueter i...@izs.me wrote: http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony Nice article, although I think the whole first section is out of place. You spend a whole page on explaining why your choice of abstraction doesn't matter. And

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Scott González
On Fri, Aug 30, 2013 at 5:24 AM, Juraj Kirchheim back2...@gmail.com wrote: On Thu, Aug 29, 2013 at 3:16 AM, Isaac Schlueter i...@izs.me wrote: http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony Nice article, although I think the whole first section is out of place. You spend

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Juraj Kirchheim
Calm your tone. It's not a lie. It's just something that you seem not to understand. If you actually care for an explanation, I will be glad to give you one. But if you're just into screaming lie at things that you cannot grasp, then I will spare both of us a further waste of time. -- -- Job

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Scott González
On Fri, Aug 30, 2013 at 8:30 AM, Juraj Kirchheim back2...@gmail.com wrote: Calm your tone. It's not a lie. It's just something that you seem not to understand. If you actually care for an explanation, I will be glad to give you one. But if you're just into screaming lie at things that you

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Dean Landolt
Many years ago I used to write functions that *almost* always returned promises, except when they didn't. And I thought it was great, and efficient. I just needed to lift the values of a *possible promises* into an actual promises using something like Q.when. This works wonderfully, until you hit

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Scott González
On Fri, Aug 30, 2013 at 9:08 AM, Dean Landolt d...@deanlandolt.com wrote: Which means you have to wrap pretty much any zalgo-promise, or use some goofy apply mechanism. Assuming you meticulously add all this boilerplate then yes, at this point Juraj is right. It solves the problem (with a

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Dean Landolt
You say this sounds like the opposite of promises solving a problem, which I assume would mean promises creating a problem? This obviously conflicts with the abstraction not mattering part. Everything I said was to reinforce the point that the abstraction doesn't matter and demonstrate how zalgo's

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Bryan Donovan
On Aug 29, 2013, at 7:09 PM, Isaac Schlueter i...@izs.me wrote: On Thu, Aug 29, 2013 at 11:19 AM, Bryan Donovan brdono...@gmail.com wrote: Thanks, I just wanted to make sure my understanding was correct in that there really is no problem with the specific case I presented. That

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Scott González
On Fri, Aug 30, 2013 at 10:15 AM, Dean Landolt d...@deanlandolt.com wrote: You say this sounds like the opposite of promises solving a problem, which I assume would mean promises creating a problem? No, they're certainly not creating a problem. It's just that the asynchrony inconsistency

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Bryan Donovan
Yeah, I really dislike this pattern. It's confusing at best. I never understood the reason for designing an API this way. I suspect it has something to do with emitting events, like in the http module. On Aug 30, 2013, at 9:48 AM, Paul pseld...@gmail.com wrote: That means never doing

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Paul
Same with us. 2 years, no problems even though Zalgo is released all over the place with error checking code. I think we get avoid any problems by just assuming that any callbacks could be called synchronously. That means never doing something that seems dirty like this: var thing =

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Scott González
You've actually highlighted the problem in your response. The part where you essentially say you're doing it wrong. The whole point of forced asynchrony is that it makes it impossible for the user to do it wrong. Yes, if we write the code in the order we want, and we always generate the promise

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Juraj Kirchheim
I believe that labeling a statement you disagree with a flat out lie is a pointlessly harsh response. But arguably calling that screaming is just as inadequate. I apologize ;) Now to the point. If you're facing this problem using promises, I would argue that you're using promises the wrong way -

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-30 Thread Trevor Norris
Just want to clarify something. process.nextTick has practically zero cost, even at the micro level. You'll only see the overhead if you're calling it 100k times/sec. Even then it's in the milliseconds. I've been doing optimizations and performance analysis on this for months. Trust me that

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Bryan Donovan
Thanks for the post, Isaac. Very helpful. I totally understand the logic of being consistent -- I'm known to be ruthless about consistency at work. I'm changing my public node.js libraries to use nextTick() instead of calling back immediately. However, I'm still unsure of when someone would

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Scott González
On Thu, Aug 29, 2013 at 12:51 PM, Bryan Donovan brdono...@gmail.com wrote: However, I'm still unsure of when someone would ever care if I called back immediately in my examples, where I'm just checking for the correct args. Oleg's generic example seemed pretty clear to me:

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Bryan Donovan
That's not the same situation though. What bad can happen in my most recent example? On Aug 29, 2013, at 9:57 AM, Scott González scott.gonza...@gmail.com wrote: On Thu, Aug 29, 2013 at 12:51 PM, Bryan Donovan brdono...@gmail.com wrote: However, I'm still unsure of when someone would ever

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Scott González
Yes, it's possible to construct specific situations that don't have problems. Nobody is denying that. But it's irrelevant if it's also possible to construct situations that do have problems. On Thu, Aug 29, 2013 at 1:50 PM, Bryan Donovan brdono...@gmail.com wrote: That's not the same situation

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Bryan Donovan
Thanks, I just wanted to make sure my understanding was correct in that there really is no problem with the specific case I presented. On Aug 29, 2013, at 11:16 AM, Scott González scott.gonza...@gmail.com wrote: Yes, it's possible to construct specific situations that don't have problems.

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Mark Hahn
But it's irrelevant if it's also possible to construct situations that do have problems. That is illogical. Code that is bulletproof is always OK. You are confusing philosophy with practice. On Thu, Aug 29, 2013 at 11:19 AM, Bryan Donovan brdono...@gmail.com wrote: Thanks, I just wanted

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Mark Hahn
But if you are talking about providing a library to others then that is not bulletproof. I was only thinking of my own code, which uses mixed sync and async all the time. On Thu, Aug 29, 2013 at 12:51 PM, Mark Hahn m...@reevuit.com wrote: But it's irrelevant if it's also possible to

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Isaac Schlueter
On Thu, Aug 29, 2013 at 9:51 AM, Bryan Donovan brdono...@gmail.com wrote: I totally understand the logic of being consistent You say this. And yet, you release Zalgo right away in your example! Never ever do this! However, I'm still unsure of when someone would ever care if I called back

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Isaac Schlueter
On Thu, Aug 29, 2013 at 11:19 AM, Bryan Donovan brdono...@gmail.com wrote: Thanks, I just wanted to make sure my understanding was correct in that there really is no problem with the specific case I presented. That understanding is incorrect. The exact problem being described in Havoc's post

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-29 Thread Hage Yaapa
The bottom line is *APIs should be consistent in behavior*. On Fri, Aug 30, 2013 at 7:39 AM, Isaac Schlueter i...@izs.me wrote: On Thu, Aug 29, 2013 at 11:19 AM, Bryan Donovan brdono...@gmail.com wrote: Thanks, I just wanted to make sure my understanding was correct in that there really

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-28 Thread Isaac Schlueter
Bryan, I wrote this for you. http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony On Fri, Aug 23, 2013 at 10:58 AM, Scott González scott.gonza...@gmail.com wrote: On Fri, Aug 23, 2013 at 1:46 PM, Chaoran Yang chaoran.y...@gmail.com wrote: I have never seen such cases ... and

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-23 Thread Oleg Slobodskoi
This all are good arguments, in the theory ... in praxis, I think: 1. Most developers do not assume async/sync mixed styles today ... 2. That kind of performance overhead matters in some rare cases, I think ... normally you don't care about 10-15ms ... If the overhead is much higher its about

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-23 Thread Chaoran Yang
On Friday, August 23, 2013 10:21:37 AM UTC-5, Oleg Slobodskoi wrote: This all are good arguments, in the theory ... in praxis, I think: 1. Most developers do not assume async/sync mixed styles today ... In practice, coding standard should not be lower because of programmer laziness,

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-23 Thread Oleg Slobodskoi
On Friday, August 23, 2013 10:21:37 AM UTC-5, Oleg Slobodskoi wrote: This all are good arguments, in the theory ... in praxis, I think: 1. Most developers do not assume async/sync mixed styles today ... In practice, coding standard should not be lower because of programmer laziness,

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-23 Thread Bryan Donovan
This is certainly only way I've ever programmed in node.js. I really don't like APIs like this: var client = connect(function() { client.do_something(function() { //.. }); }); … they're just weird. This makes a lot more sense to me:

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-23 Thread Chaoran Yang
Depends on how much pain it causes ... If official nodejs doc warns people then its probably fine ... I just found out official nodejs doc has that in there, which is a very bad idea I think. I have never seen such cases ... and can't imagine them ... but potentially yes ... The

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-23 Thread Scott González
On Fri, Aug 23, 2013 at 1:46 PM, Chaoran Yang chaoran.y...@gmail.comwrote: I have never seen such cases ... and can't imagine them ... but potentially yes ... The cursor.nextObject() of node-mongodb-nativehttps://github.com/mongodb/node-mongodb-native/blob/master/lib/mongodb/cursor.js#L678

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-22 Thread Oleg Slobodskoi
Here is another real world example: var todo = 0; function done() { todo--; if (!todo) callback(); } todo++; // If a calls back synchronously, todo amount will never be 2, so done will call back directly after a calls back. a(done); if (soemthing) { todo++; b(done); }

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-20 Thread Scott González
The potential issue is if the person consuming your API expects the callback to always be async: // kick off the async process as early as possible doAsync( cb ); // do some slightly high cost prep work before the callback is invoked prepareStateForCallbackWhileWaiting(); Doing the prep work

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-20 Thread Aria Stewart
On 20 August 2013 at 1:47:45 PM, Bryan Donovan (brdono...@gmail.com) wrote: I have been writing node.js client code for a couple of years now, and have authored a couple open source libraries, but somehow I missed the memo telling me that I'm supposed to wrap 'synchrounous' callbacks in

[nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-20 Thread Bryan Donovan
I have been writing node.js client code for a couple of years now, and have authored a couple open source libraries, but somehow I missed the memo telling me that I'm supposed to wrap 'synchrounous' callbacks in process.nextTick(). I kind-of understand why that is a best-practice, but what I

Re: [nodejs] Downside to not wrapping sync callbacks in nextTick()?

2013-08-20 Thread Bryan Donovan
Thanks Scott. That's basically what I had gathered from googling around. It seems to me like it's not necessary to wrap in nextTick for most cases then. On Aug 20, 2013, at 10:58 AM, Scott González scott.gonza...@gmail.com wrote: The potential issue is if the person consuming your API