On Jul 7, 2006, at 1:08 PM, Guido van Rossum wrote: > On 7/7/06, Ka-Ping Yee <[EMAIL PROTECTED]> wrote: >> I've been doing a bunch of Firefox extension programming in >> Javascript >> and suddenly a few of the recent topics here came together in my head >> in a silent kapow of thoughts. This is kind of a side note to the >> security discussion, but they're all interconnected: network >> programming, concurrency, lexical scoping, security. > > Hm... I wonder if this style has become so popular in JS because it's > all they have? I find callback-style programming pretty inscrutable > pretty soon.
You really don't have any choice without continuations or some built- in concurrency primitive. Callbacks are slightly less painful in JavaScript because you can define them in-line instead of naming it first. >> Client-side web scripting tends to have a callback/continuation-ish >> concurrency style because it has to deal with network transactions >> (which can stall for long periods of time) in a user interface that >> is expected to stay always responsive. The Firefox API is full of >> listeners/observers, events, and continuation-like things. So one >> thing to consider is that, when Python is used for these purposes, >> it may be written in a specialized style. >> >> As i write JavaScript in this style i find i use nested functions >> a lot. When i want to set up a callback that uses variables in the >> current context, the natural thing to do is to define a new function >> in the local namespace. And if that function has to also provide a >> callback, then it has another function nested within it and so on. >> >> function spam() { >> var local_A = do_work(); >> do_network_transaction( >> new function(result_1) { >> var local_B = do_work(result_1); >> do_network_transaction( >> new function(result_2) { >> do_work(local_A, local_B, result_1, >> result_2); >> ... >> } >> ); >> } >> ); >> } > > How can you ever keep track of when a '}' must be followed by a ';' ? "}\n" is the same as "};" as far as the JavaScript spec goes, you can do either or both. -bob _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com