Re:The Node Ahead: JavaScript leaps from browser into future
by judofyr on Tuesday March 01, 2011 @03:39PM
(#2277095)
There is no way of doing I/O in JavaScript's traditional browser environment
without providing a callback argument.
What about `window.prompt`? Or `document.write`?
Re:The Node Ahead: JavaScript leaps from browser into future
by lalc on Tuesday March 01, 2011 @03:47PM
(#2277128)
http://www.boctaoe.com/
(Man, I just learned about this site five minutes ago and it's already useful!)
Re:The Node Ahead: JavaScript leaps from browser into future
by randylahey on Tuesday March 01, 2011 @06:31PM
(#2277745)
I would hardly call window.prompt and document.write i/o since they never hit disk or network (to over-simplify). They're more like manipulating an object in memory.
For real i/o in JavaScript, look at AJAX: Callback based.
Re:The Node Ahead: JavaScript leaps from browser into future
by Ramone on Tuesday March 01, 2011 @07:31PM
(#2277942)
Conversely, some might say that input from the user and output to the user are really the only important i/o.
Re:The Node Ahead: JavaScript leaps from browser into future
by andrewvc on Tuesday March 01, 2011 @10:09PM
(#2278297)
You are entirely right. In my mind use asynchronous for what it is good for, but use as little as possible. Delegate app logic to a synchronous threaded worker pool unless you absolutely cannot.
I think this idea of a constrained environment is very important. If blocking I/O functions are strewn about the APIs you have at your disposal, then programmers tend to default to using them.
The other point he makes is that often evented APIs are just missing from the underlying platform. Does every way of doing some sort of I/O in the universe of Python APIs have variants that take callback arguments? Even if the answer is 'yes' (which would surprise me) there is a minefield of blocking calls one would need to avoid in a disciplined manner.
...which may not be easy. Tell me: does myAwesomeFunction() do some blocking I/O under the hood? You can't tell from the name. Do the docs always make that clear, and provide an alternative with a callback?
Edited to include judofyr's exceptions — which bolster rather than undermine the point, because note that window.prompt's raison de'etre is to block for user interaction, and document.write is a RAM operation rather than disk or network I/O.