On Wed, Apr 12, 2017 at 12:29 PM, Rustom Mody <rustompm...@gmail.com> wrote: > > I wonder if you notice Steven, that people use these examples to make > the opposite case? > > When you see "python is sweet... almost as sweet as javascript" > > you know you are in trouble and need to start running (at least I do) > > http://stackabuse.com/python-async-await-tutorial/ > [last para]
Ah, yes, because JS's generators are so smooth compared to Python's. The fact that yielded values get packaged up into {value: ..., done: false} makes so much more sense, plus it's hugely advantageous that you need to transpile your code to be able to actually use async functions in anything other than the latest Chrome/Safari/Firefox. There are two areas where JS has a really significant advantage over Python: 1) Invoking a JS async function is as simple as calling it, because you already are running everything through an event loop. I don't think Python should do the same, but maybe a more obvious way to do this than ensure_future would help. 2) If you have existing code that is built on JS's promises (of which there's a lot, but by no means all), async functions cleanly interface with them. You can await any promise, and an async function automatically returns a promise. So they're better integrated with the rest of the ecosystem - or at least, that portion of the ecosystem that jumped on the promise bandwagon. Got something that only uses callbacks? Sorry, mate, you're out of luck. Both of them come from the fact that JS has always been intended as an asynchronous language - right back in the 90s, before it was all standardized as ECMAScript, you had a setTimeout() function rather than a sleep(). Python, meanwhile, has made it easy to write blocking I/O in a single-threaded program, and then adds async'ness to it. So with JS, you're adding smoothness to functionality that already exists, but with Python, you're adding functionality to a smooth and clean language. ChrisA -- https://mail.python.org/mailman/listinfo/python-list