3 ms·
This argument basically boils down to "I think elegant abstractions are more important than readable code". This is a pretty valid position to hold, but I stron
by skrebbel 11y ago
This argument basically boils down to "I think elegant abstractions are more important than readable code". This is a pretty valid position to hold, but I strongly doubt the majority of the JS community agrees.
A similar thing is how when you return a Promise from a 'then' callback, the resulting promise does not resolve to an inner promise but just to the value that was inside the inner promise. This completely breaks the monadic properties of Promise, but given that JS has no nice support for monads, it makes code simpler and easier.
IMO, but Promises/A+ spec designers made the right call here. Purists will disagree, but I bet the majority of the JS community hasn't even given this a thought (yet uses the feature all the time). I feel the same about async/await.
Also, anecdotally, at my company we're heavy heavy users of async/await ever since Babel added support for it, and we've yet to run into any of the problems the author refers to.
- omgtehlion 11y agoIn my current project we were using async/await even before they appeared in Babel (via homegrown transpiler). Been happy so far.
- tracker1 11y agoI have to agree... just because someone may have a case where they need multi-stage transactions or cancellable workers doesn't mean that Promises and async/await aren't useful as they stand. I wrote a ton of code last year to migrate data from one system to another... without async/await, Promises and node-style streams, it would have been really nasty, deeply nested code... as it was, the flows were fairly functional, really elegant, and worked extremely well. I will say that Bluebird is useful beyond what the Promises spec offers, and have gone back and forth between using it, replacing the native Promise where available and just using whatever promise shim or native is available. I didn't like promises earlier on, as without some of the extras that async functions offer, I didn't consider them much better than callbacks. Now, I'm sold.
- spion 11y agoNot sure what you mean by multi-stage transactions? It applies for ordinary transactions - its just a way to avoid passing a transaction parameter everywhere but still guaranteeing that the entire batch of queries executed within a single transaction. I don't think the problems I'm describing here are all that uncommon in server-side code. Continuation local storage (the equivalent of thread local storage) in particular seems to be an often requested feature by many users in node.
- maxthegeek1 11y agoThe issue is that we could have landed on syntax that was both more readable and allowed for elegant abstractions.
- braythwayt 11y ago> "I think elegant abstractions are more important than readable code” Typically, that is not the argument. Typically, the argument is that the "elegant abstraction" is just as readable, just in a different way. And further, the typical argument for elegant abstractions is that the “readable code” option is usually most readable for a specific, narrow problem to solve, and that it breaks down when you try to do more complicated things. So if you buy the argument in favour of elegant abstractions, you are trying to make “simple things simple, and complicated things possible.” Whereas the argument in favour of special keywords and other special-purpose constructions is that they also make simple things simple, but do little to make complicated things possible. The argument in favour of languages having these “readability” constructs is actually that they foster standardization, which makes them readable by virtue of the fact that everyone settles on doing them the same way. Which means in fact that they aren’t more readable in an isolated, objective sense. They’re actually more familiar. That has value in its own right, of course. But I don’t think the author--or anyone else who isn’t thrilled by some of the TC-39 choices--is arguing that there is an elegance vs. readability dichotomy. In actual fact, the argument is between elegance and familiarity by fiat.