7 ms·
function foo() { return doSomething(); } async function doSomething() { ... throw ScanError(); } Spot the bug? That's an async function. Eve
by sillysaurus3 8y ago
function foo() {
return doSomething();
}
async function doSomething() {
...
throw ScanError();
}
Spot the bug? That's an async function. Every JS programmer worth their salt will tell you how many times they've been annoyed to discover a missing await, and that the promise is failing mostly-silently (or worse, it works by accident until it doesn't, since that code will work fine most of the time).
Well JS does provide this via exceptions.
Second it's totally crazy that emacs depends on longjmp
It's not crazy.
function bar() {
[1,2,3].forEach(x => {
if (x == 2) /* return from bar...? */
}
}
Why can't you write this code? I mean you "can":
function bar() {
let tag = [];
try {
[1,2,3].forEach(x => {
if (x == 2) { tag.value = x; throw tag; }
}
} catch (e) {
if (e === tag) {
return e.value;
}
}
But holy crap that's terrible. EDIT: I also forgot to rethrow the error, showing just how easy it is to screw up.
Just write it as a for loop, then. Well sure, except for the hundreds of libraries that don't support that style. What do you do when you want to return prematurely from the iterator functions you pass to them? Now you can't just make a for loop unless they provide Symbol.iterator. And 9 times out of 10 they give you a promise, meaning you're forced to convert your code to async style.
It's a huge mess, and longjmp saves you a lot of headaches in disciplined situations. Every tool has its place, and it's strange to argue that a computer should be able to do less, not more.
The goal is to save you time in the long run. And those 5 lines better be exactly right, or you'll waste a lot.
- gear54rus 8y agojust use one of myriad array methods available, like "find" for this case "can't write some class of software" is just wrong, is all