3 ms·
Interesting write up, examples, and ideas, but the conclusion is a bit silly: >Lets drop async/await and write our own interpreters. Guess what kind of "inter
by amasad 11y ago
Interesting write up, examples, and ideas, but the conclusion is a bit silly:
>Lets drop async/await and write our own interpreters.
Guess what kind of "interpreter" most people would need? The async/await kind. It doesn't solve everything and it does introduce more awkwardness[1] to the language but it's categorically a productivity and readability boost. Now to address the individual points raised:
1. Try/Catch
The argument here is against a core language feature and has nothing to do with async/await. Sure, guarded catch statements would be nice, but I contend that if you're relying on multiple levels of exception handling then you're using exceptions for flow control.
2. Higher order functions
JavaScript is a multi-paradigm language and as mentioned earlier that leads to awkwardness. You can only pull the language in so many directions before it becomes inconsistent. Some features will be geared towards functional paradigms and other will be imperative by nature. For example instead of `forEeach` you can use `for of` which allows you to yield inside the loop. In that sense async/await, for-of, and try/catch are all imperative control flow constructs. On the other hand callbacks, promises, and higher order functions are functional constructs. Mixing them together is not easy (nor should it be if you ask me).
3. "generality"
In this case you might not want to use such a high-level construct like async/await. Just like when you have to do caching or memoization you tend to drop down to do promises again. However, you can push this down into a library that exposes a promise and then continue using async/await in the rest of your application. In this specific case you want a monad-like abstraction, something that carries certain context across a sequence of computations. The generator implementation might be an overkill but the syntax looks nice.
[1]: This is a great write up on how adding different types of functions to the language makes it awkward to say the least: http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...
- true_religion 11y ago> The argument here is against a core language feature and has nothing to do with async/await. Sure, guarded catch statements would be nice, but I contend that if you're relying on multiple levels of exception handling then you're using exceptions for flow control. I don't see how this is a problem. Try/Catch are by definition flow control keywords. Also, when you get an exception you have to differentiate between how you recover from it or package it into something that can be logged or used by a higher level caller. That said, I don't disagree with any of your other statements.
- spion 11y ago> Guess what kind of "interpreter" most people would need? The async/await kind. Because we never got the chance to explore the full power of generators, and we probably never will because of it. We will of course solve our other problems the usual old-fashioned way (e.g. DI for transactions, some other funky mechanisms for CLS, no automatic SQL query optimizations, no automatic GraphQL query optimizations). You can't need what you aren't aware of. > The argument here is against a core language feature and has nothing to do with async/await. Not directly, no, but thanks to async/await a lot more errors will be flying up the call stack than ever before. This will greatly increase the chances that you catch something you didn't intend to catch. Unless you have filtered catch, which would improve that a little bit.