←back to thread

320 points willm | 6 comments | | HN request time: 0s | source | bottom
1. throwawayffffas ◴[] No.45109435[source]
The function coloring is a non starter for me.

I would just rather write JS where everything is async by default.

replies(1): >>45109493 #
2. IshKebab ◴[] No.45109493[source]
Everything is not async by default in JS.
replies(2): >>45109573 #>>45110137 #
3. throwawayffffas ◴[] No.45109573[source]
I mean everything is running on the runloop, async/await, promises, and callbacks are different flavors of syntactic sugar for the same underlying thing.

In JS you can do:

   async function foo(){...}
   function bar(){foo().then(...);}
In python though async and sync code runs in a fundamentally different way as far as I understand it.
replies(1): >>45109696 #
4. IshKebab ◴[] No.45109696{3}[source]
I'm not too familiar with Python async. The only time I used it was to get stderr and stdout out of a subprocess.run() separately. I think anyone using it for performance reasons is insane and should just switch to a more performant language.

Anyway I think the main difference is that in Python you control the event loop whereas in JS there's one fixed event loop and you have no choice about it.

5. fzzzy ◴[] No.45110137[source]
I think what they mean is that there are no blocking functions in the standard library except alert, prompt, and confirm. ( are there any others?)
replies(1): >>45112808 #
6. steve_adams_86 ◴[] No.45112808{3}[source]
Yeah, you can call async functions without specifying it as such and the script will just carry on regardless of how you're handling it. Totally weird, but also pretty cool. When I first started some 20 years ago that was a major foot gun for me, coming from PHP where functions always returned before the next one was called.