This worries me. Imagine some fake code like this:
function f(x, y) {
switch(x) {
case 1: goto a;
case 2: goto b;
case 3: goto c;
}
a: do_foo(y); return;
b: do_bar(y); return;
c: do_other_stuff(y); return;
}
Calls to it would look like f(1), f(2, "cat"), f(3, "dog"). It's horrible, but at least you see the first arg changing to get some idea of what's going on.
This yield thing makes it possible to call the same function with the same arguments and get completely different behavior depending on how far along it's managed to get.
In that situation, f("cat") != f("cat") != f("cat"), and that just seems scary to me.
(BTW, I am aware that JS doesn't do goto. But this basically adds it in, kinda-sorta.)
Like so many things, I'm sure it can be used for great evil or great justice, but I don't have a whole lot of faith in people to do the right thing with it.
Isn't this just the same situation we already have right now where a function can have different results if one of the hidden variables it closed over has mutated?
This yield thing makes it possible to call the same function with the same arguments and get completely different behavior depending on how far along it's managed to get.
In that situation, f("cat") != f("cat") != f("cat"), and that just seems scary to me.
(BTW, I am aware that JS doesn't do goto. But this basically adds it in, kinda-sorta.)
Like so many things, I'm sure it can be used for great evil or great justice, but I don't have a whole lot of faith in people to do the right thing with it.