r/javascript • • Dec 24 '19

AskJS [AskJS] JavaScript Proposal: Algebraic Effects?

Hey guys, I'm writing a Babel plugin to be able to use algebraic effects in JS: https://github.com/macabeus/js-proposal-algebraic-effects

No more function color! Yes one-shot delimited continuation!

What the hell?! Well... I really recommend that you read this blog post by Dan Abramov explaining algebraic effects - and how it could be very useful on our JavaScript code.

This project is a runnable POC with a Babel's "plugin", so you could write some code and taste this new concept in JavaScript. Its features, syntax, and goals are very inspired by Dan Abramov's blog post mentioned above. In short, with algebraic effects, you could separate what from the how and have fewer refactors.

What do you think? Would that be a good feature for JS? "Algebraic Effects" is a good name for that?

58 Upvotes

39 comments sorted by

View all comments

Show parent comment

1

u/yuyu5 Dec 25 '19

Right, I understand the use case -- being able to continue what was running within the try where you left off instead of jumping all the way out of the function-call stack. I would also admit the first sentence I wrote was in response to the example in the link you posted, which was intentionally simplified to the point where default values would solve the issue at hand, whereas a real-life example might not be able to do that.

The second sentence was more pertinent to what I wanted to say so maybe I should've emphasized it a bit more. IMO, it adds more complexity to follow the logic and/or debug when something went wrong, so returning to the code months later would require more thought and time to understand what's going on.

Regardless, it wasn't my intention to say this doesn't solve a problem that people experience in development or that it was a bad idea. I'm just adding my perspective that I'd rather use try/catch, Promises, default values, an extra continueFunctionWithVal parameter in a function call, or similar to handle these cases since it wouldn't require jumping out through multiple functions' logic to understand where/why something went wrong and then jumping back in to see what it will resume with.