3 ms·
Much cleaner. You can go even further by using point-free style: get().then(set) It's the try/catch blocks that make async/await truly worse than native p
by Rumudiez 6y ago
Much cleaner. You can go even further by using point-free style:
get().then(set)
It's the try/catch blocks that make async/await truly worse than native promises. I use them sparingly because so often the .then syntax is both clearer and terser.
- postalrat 6y agoWhat don't you like about try/catch? I find the opposite true, the .then/.catch is more confusing.
- Rumudiez 6y agotry/catch introduces new block scopes and interrupt control flow. I find this example very readable, but expanding it into try/catches would make it rather long winded and harder to see the pattern at work as you extend the sequence: get() .then(handleResult) .catch(useFallbackResult) .then(updateState) I prefer concision and functional expressiveness because it reduces the surface area for writing buggy code. Much like how using map instead writing a for loop can eliminate out of range index bugs, chaining promises brings useful guarantees about how the code I do write can be interpreted.