Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-20 Thread Jose Luis Rivas
On 8/21/13 12:03 AM, Tim Smart wrote: > Sorry, one more time: https://gist.github.com/tim-smart/6290338 > > A simple state object makes a heap of difference in terms of code > nesting. I'm not too sure if it has performance implications. Hey Tim, why don't use waterfall from async to accomplish t

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-20 Thread Tim Smart
Sorry, one more time: https://gist.github.com/tim-smart/6290338 A simple state object makes a heap of difference in terms of code nesting. I'm not too sure if it has performance implications. On 21 August 2013 16:28, Tim Smart wrote: > One other rule that I use a lot, is a state object: > > > >

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-20 Thread Tim Smart
One other rule that I use a lot, is a state object: On 21 August 2013 07:11, Mark Hahn wrote: > We are down to just opinions so I'll shut up now. > > On Tue, Aug 20, 2013 at 11:57 AM, Andrew Kelley > wrote: >> >> I'm not going to remove mention of the fact that coffee-script does not >> suppor

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-20 Thread Mark Hahn
We are down to just opinions so I'll shut up now. On Tue, Aug 20, 2013 at 11:57 AM, Andrew Kelley wrote: > I'm not going to remove mention of the *fact* that coffee-script does not > support function hoisting, which is the *main suggestion *of the style > guide. Your "only algorithm change" destr

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-20 Thread Andrew Kelley
I'm not going to remove mention of the *fact* that coffee-script does not support function hoisting, which is the *main suggestion *of the style guide. Your "only algorithm change" destroys the ability to put "synchronous code" first, followed by purely a list of function declarations, which is

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-20 Thread Mark Hahn
> I meant to show that applying this pattern without knowing what it actually does can lead to cases where it simply doesn't work. Of course if someone doesn't apply the pattern correctly it won't work. This is true for all patterns. There is nothing inherently dangerous about this one. I don't

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-20 Thread Floby
Did you read the examples I provided ? Of course the code you posted works. I meant to show that applying this pattern without knowing what it actually does can lead to cases where it simply doesn't work. OF COURSE, doing things without knowing how they actualy do is stupid anyway... so :) On M

[nodejs] Re: Callbacks are Pretty Okay

2013-08-19 Thread Sopl Wang
Agree, totally. I idea is there has no callback, but function object (or closure, or block), simple and stupid, and natural. -- wenlin 在 2013年8月17日星期六UTC+8下午1时53分26秒,Andrew Kelley写道: > > I wrote this article as a response to all the recent callback hate: > > http://andrewkelley.me/post/js-callb

[nodejs] Re: Callbacks are Pretty Okay

2013-08-19 Thread Lucas Schmidt
The real issue regarding callbacks in my mind is when you have to deal with errors. Its just a ridiculous pain to check for errors everywhere. I got to the point where I have to use promises, just to be able to use that fail handler. Really, if you stop to think about it, A LOT of time, you s

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-19 Thread tomByrer
On Sunday, August 18, 2013 2:36:47 PM UTC-6, Mark Hahn wrote: > > start = -> setTimeout cb1, 1000; console.log Date.now() > cb1 = -> setTimeout cb2, 1000; console.log Date.now() > cb2 = -> console.log Date.now() > > start() > > ... > Does anyone appreciate this pattern? It is like the pattern de

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-19 Thread Mark Hahn
> I said the code I posted wasn't working on coffeescript. But yours does in certain cases. The actual code I posted always works. The coding pattern I am suggesting always works. It wouldn't be very useful otherwise. -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github

[nodejs] Re: Callbacks are Pretty Okay

2013-08-19 Thread Floby
My opinion on coffeescript, for what it's worth, is that I find it hard to understand without knowing what it compiles to. On Saturday, 17 August 2013 07:53:26 UTC+2, Andrew Kelley wrote: > > I wrote this article as a response to all the recent callback hate: > > http://andrewkelley.me/post/js-ca

[nodejs] Re: Callbacks are Pretty Okay

2013-08-19 Thread Floby
To be clear. I said the code I posted wasn't working on coffeescript. But yours does in certain cases. coffeescript: myThing.onEvent myHandler myHandler = -> ^ This works, assuming the given event will be emitted some time in the future, once the call stack has unfolded. coffeescript: myColle

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-19 Thread klrumpf
for one I'm using it and happy with it On 19/08/13 02:37, Mark Hahn wrote: I agree with everyone, although I don't think it is a hack. I'm very happy that we all understand each other now. I just wanted to put this option out there. There seemed to be a general consensus that this wasn't p

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Mark Hahn
I agree with everyone, although I don't think it is a hack. I'm very happy that we all understand each other now. I just wanted to put this option out there. There seemed to be a general consensus that this wasn't possible in coffeescript and I wanted to provide this counter-opinion. I do feel

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Brett Ritter
On Sun, Aug 18, 2013 at 1:36 PM, Mark Hahn wrote: > > Yes, I know it isn't hoisting. I never claimed it was. I'm just saying (over and over) that callbacks can call the functions while going downwards in the file. This is how I code everything. So that's the key. Coffeescript requires a certa

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Nathan Rajlich
Mark, I think the point everyone is trying to make is that with regular JavaScript, this "start()" thing is *not* necessary, but with CoffeeScript it is... essentially, this "start()" mechanism is a hack for CS's lack of function hoisting. On Sun, Aug 18, 2013 at 1:36 PM, Mark Hahn wrote: > Yes

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Mark Hahn
Yes, I know it isn't hoisting. I never claimed it was. I'm just saying (over and over) that callbacks can call the functions while going downwards in the file. This is how I code everything. Here is a more detailed example. Note how readable it is when the control flows downward, just like syn

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Stephen Belanger
That is calling a function that is defined in an upper context. It IS defined before the call, as the body of start does not run until the last line. That is NOT hoisting, that is a result of Javascript exposing the upper context by memory reference rather copying the memory at the time of defining

Re: [nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Mark Hahn
I know coffeescript functions don't hoist. I've been coding in nothing but coffeescript for almost three years. Hoisting *is* needed to call a definition that hasn't been encountered yet in time. But hoisting is *not* needed to call a function defined further down in the file. It's the differen

[nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Floby
Also Ryan Dahl once outlined a single rule to avoid callback hell. 1. Set your editor column limit to 80. On Saturday, 17 August 2013 07:53:26 UTC+2, Andrew Kelley wrote: > > I wrote this article as a response to all the recent callback hate: > > http://andrewkelley.me/post/js-callback-organizati

[nodejs] Re: Callbacks are Pretty Okay

2013-08-18 Thread Floby
Point being, there is no way to make coffeescript generate hoisted function statements. It only generates assignments with function expressions. On Saturday, 17 August 2013 07:53:26 UTC+2, Andrew Kelley wrote: > > I wrote this article as a response to all the recent callback hate: > > http://andr

[nodejs] Re: Callbacks are Pretty Okay

2013-08-17 Thread Filipe Deschamps
Perfect approach! I'm going to start using it, thanks! On Saturday, August 17, 2013 2:53:26 AM UTC-3, Andrew Kelley wrote: > > I wrote this article as a response to all the recent callback hate: > > http://andrewkelley.me/post/js-callback-organization.html > > It contains: > >- Acknowledgement