On Tue, Aug 6, 2013 at 7:07 PM, Mark Hahn <m...@reevuit.com> wrote: > Also, the constructor problem would break immediately, not at some random > later time.
Can you explain how any or all of these being generator functions: a() b() c() ... will break at some random later time? Assuming that those three calls represent some user code. Rick > > > On Tue, Aug 6, 2013 at 4:06 PM, Mikeal Rogers <mikeal.rog...@gmail.com>wrote: > >> >> On Aug 6, 2013, at 3:57PM, Rick Waldron <waldron.r...@gmail.com> wrote: >> >> >> >> >> On Tue, Aug 6, 2013 at 6:17 PM, Mark Hahn <m...@reevuit.com> wrote: >> >>> > Always assume that you will be suspended any time you have a yield or >>> yield* >>> >>> How do you know any of this you see a function call? Only the function >>> definition looks different. Tell me which is these will yield .. >>> >>> a() >>> b() >>> c() >>> >> >> I see no reason why it would matter if any or all of these are generator >> functions. How is this argument any different then calling constructor >> functions with new or not? >> >> Tell me which of these is a constructor that must be called with `new`: >> >> a() >> b() >> c() >> >> >> None of them, they aren't capitalized. This is a trick question right? >> >> :P >> >> >> >> Rick >> >> >> >> >> >>> >>> On Tue, Aug 6, 2013 at 2:54 PM, Tim Caswell <t...@creationix.com> wrote: >>> >>>> >>>> >>>> >>>> On Tue, Aug 6, 2013 at 4:47 PM, Mikeal Rogers >>>> <mikeal.rog...@gmail.com>wrote: >>>> >>>>> It is the *exact same* hazard as the code you posted, I don't think it >>>>> is any *more* of a hazard at the language level. The difference is that >>>>> the >>>>> pattern in the function code below is basically never seen in node.js code >>>>> and it has been *possible* to write it since node's creation. >>>>> >>>>> Could be that nobody will use/clobber closure scope in their >>>>> generators either, but I'm afraid they will because it will work and >>>>> operate as expected *most* of the time and, unlike the function example >>>>> you've posted, it will still fit well when used with what I assume will >>>>> become a healthy ecosystem of generator consuming libraries. >>>>> >>>>> The reason nobody writes this kind of thing in node is that it just >>>>> won't play well with the rest of the libraries in the ecosystem whereas >>>>> the >>>>> hazardous generator example looks like it would fit just as well as a >>>>> "well >>>>> written" generator until it hits scale and causes visible bugs. >>>>> >>>>> All kinds of bad patterns and bad code are possible in any language. >>>>> The patterns we adopt to create a healthy ecosystem are what will keep >>>>> people away from the third rails. Depending on people to have "well >>>>> written" code, by some definition of "well", is not a good alternative to >>>>> solidifying and encouraging patterns that make it *difficult* to write >>>>> hazardous code in the first place. >>>>> >>>>> No pattern or feature in JavaScript escapes the potential for abuse >>>>> and bugs, and nothing that I'm worried about w/ respect to generators is >>>>> worse or better than language level hazards w/ callbacks, it's just that >>>>> we've created a set of patterns that *discourage* those hazards in the >>>>> current ecosystem and I'm failing to see how we do that in this particular >>>>> case with generators. >>>>> >>>> >>>> I propose a simple rule for all generator code: >>>> >>>> - Always assume that you will be suspended any time you have a yield >>>> or yield* and any shared state may change. >>>> >>>> If we educate everyone and focus on that one thing (yield) that will >>>> cover all hazards around shared state and generators, be it async >>>> promise/continuable based stuff or sync lazy iterator stuff. >>>> >>>> Just like with functions we've learned to look for the "function" >>>> keyword and guard our state around that point, we need to do the same >>>> around the "yield" keyword. >>>> >>>> Teach people correct principles and trust them to do the right thing. >>>> We'll be fine. >>>> >>>> >>>> >>>>> >>>>> -Mikeal >>>>> >>>>> On Aug 6, 2013, at 2:33PM, Tim Caswell <t...@creationix.com> wrote: >>>>> >>>>> My question to people on the list is how is this any different than >>>>> the same hazard with normal function? >>>>> >>>>> var sum, i; >>>>> function reduce(arr) { >>>>> sum = 0; >>>>> i = 0; >>>>> return function () { >>>>> if (i < arr.length) { >>>>> sum += arr[i++]; >>>>> return sum; >>>>> } >>>>> }; >>>>> } >>>>> >>>>> >>>>> >>>>> -- >>>>> -- >>>>> 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 >>>>> >>>>> --- >>>>> 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 nodejs+unsubscr...@googlegroups.com. >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>>> >>>>> >>>> >>>> >>>> -- >>>> -- >>>> 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 >>>> >>>> --- >>>> 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 nodejs+unsubscr...@googlegroups.com. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>> >>> >>> -- >>> -- >>> 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 >>> >>> --- >>> 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 nodejs+unsubscr...@googlegroups.com. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> >> -- >> -- >> 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 >> >> --- >> 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 nodejs+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> -- >> -- >> 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 >> >> --- >> 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 nodejs+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > -- > 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 > > --- > 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 nodejs+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- 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 --- 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 nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.