Live data from Hacker News

Algebraic Effects for React Developers

reesew.io

11–20 of 98 posts

Re: Algebraic Effects for React Developers

#11
Hooks are not functional. The most elementary rule of functional programming is no state and no side effects. If you break these rules and justify your rule-breaking by pointing to esoteric concepts then you're violating the spirit of functional programming.

Thanks to React Hooks a whole generation of JavaScript programmers are being misled into believing they are doing functional programming when they're really not. More on that here: https://medium.com/weekly-webtips/dysfunctional-programming-...

Re: Algebraic Effects for React Developers

#12

Hooks are not functional. The most elementary rule of functional programming is no state and no side effects. If you break these rules and justify your rule-breaking by pointing to esoteric concepts then you're violating the spirit of functional programming. Thanks to React Hooks a whole generation of JavaScript programmers are being misled into believing they are doing functional programming when they're really not.…

Is OCaml functional?

Re: Algebraic Effects for React Developers

#13
I've read a bit about algebraic effects in the past (independent of React), but I think they are much harder to grok than hooks. I tried many times but I never really got it. Like Haskell has this way of making you think you've got it for a split second, then you try to do something and you realise you don't have a clue. The effect systems using free monads seem to keep applying a functor to itself an unlimited amount of times and I really didn't get it. I even did that category theory youtube course for programmers. Still don't get it. I could probably get it if I went full time on just that for 2 months or so, then coded in that style for a year to really bed it in.

Anyway...

However I don't find hooks that hard to understand. I don't think you need to touch algebraic effects to get it. It's yet another view system (like having done windows forms, wpf, asp.net webforms, mvc, knockout js, RX, etc.) to get your head around how it works.

In this case you have a function that returns the desired state and with useEffect you can set up actions to be run after that view gets rendered and added to the DOM, with some conditions on which renders you are interested in (all of them? just when foo changes?). And another callback for when you are "done" so you can clean up.

Re: Algebraic Effects for React Developers

#14

Hooks are not functional. The most elementary rule of functional programming is no state and no side effects. If you break these rules and justify your rule-breaking by pointing to esoteric concepts then you're violating the spirit of functional programming. Thanks to React Hooks a whole generation of JavaScript programmers are being misled into believing they are doing functional programming when they're really not.…

IO isn’t (typically) functional, and neither is the IO monad. But like reference types in Clojure, it’s how you express “the world is stateful, my program usually is not, but for this exceptional case my program interfaces with the world.” I don’t think React hooks are a good way to signal that, but they’re one of the ways people who prefer FP in real world use do it. I think Redux type solutions are a better signal in some cases, and the rare stateful class component has is better in others. I hope hooks don’t take over the React ecosystem, but if they do I’ll be looking for other solutions similar to earlier React with regular functions and stateful escape hatches.

Re: Algebraic Effects for React Developers

#15

Hooks are not functional. The most elementary rule of functional programming is no state and no side effects. If you break these rules and justify your rule-breaking by pointing to esoteric concepts then you're violating the spirit of functional programming. Thanks to React Hooks a whole generation of JavaScript programmers are being misled into believing they are doing functional programming when they're really not.…

Is OCaml functional?

Pure functional languages such as Haskell have some facilities to do things that are not 100% pure, such as I/O. Similarly, OCaml has effects, but functional programmers minimize their use of such impure facilities.

Effects in OCaml are impure: "However, the effect system also allows for tracking side-effects more generally. It distinguishes impure functions, which perform side-effects, from pure functions, which do not." See: https://www.janestreet.com/tech-talks/effective-programming/

In Haskell impure functions are fenced off from pure functions. So for example, pure functions are not allowed to call impure ones.

If nearly all of the functions in your app are impure (and use React hooks) then you are definitely not doing functional programming.

Re: Algebraic Effects for React Developers

#16

Hooks are not functional. The most elementary rule of functional programming is no state and no side effects. If you break these rules and justify your rule-breaking by pointing to esoteric concepts then you're violating the spirit of functional programming. Thanks to React Hooks a whole generation of JavaScript programmers are being misled into believing they are doing functional programming when they're really not.…

IO isn’t (typically) functional, and neither is the IO monad. But like reference types in Clojure, it’s how you express “the world is stateful, my program usually is not, but for this exceptional case my program interfaces with the world.” I don’t think React hooks are a good way to signal that, but they’re one of the ways people who prefer FP in real world use do it. I think Redux type solutions are a better signal…

IO isn't functional and that's the reason FP languages such as Haskell have a system for dealing with functions that have side-effects, that neatly separates the part of the program that is pure and the part of the program that is impure (and does all the dirty work like updating the screen). Impure parts of the program is fenced off from the pure parts. Pure functions cannot call impure functions.

The important part here is keeping portions of your code that has side-effects separate — and minimizing the amount of such code. If code that has side-effects is spread all over your program then you are not really using functional style.

More on that here: https://medium.com/weekly-webtips/dysfunctional-programming-...

Re: Algebraic Effects for React Developers

#17

I started learning React for starting a large project a few months ago. I have not really liked the experience very much. One seems to still need to know all the JS/CSS/HTML I've been using for 10+ years but also a new stack on top of it, simultaneously. Hooks are one of the strangest features I've seen in a language yet. I doubt they will be a lasting paradigm outside of the React ecosystem. I like JSX a lot. The id…

You might want to watch this https://www.youtube.com/watch?v=i__969noyAM (2014) to see why React exists and the sort of problem it solves.

But now in 2020 you have 2 reasons to pick React. One is because it's the right tool. The second is to do with the JS tech battlefield - you pick React because it won the front-end popularity fight, and is probably safe for the next 5 years, and you can hire React developers, and you can hire them knowing they will want to stay React developers etc. Yes all that BS!

Also you might pick React for your own CV!

Let's be honest!!

Re: Algebraic Effects for React Developers

#18

I started learning React for starting a large project a few months ago. I have not really liked the experience very much. One seems to still need to know all the JS/CSS/HTML I've been using for 10+ years but also a new stack on top of it, simultaneously. Hooks are one of the strangest features I've seen in a language yet. I doubt they will be a lasting paradigm outside of the React ecosystem. I like JSX a lot. The id…

Something is off with your transpiling set up if you’re not getting accurate stack traces. A “create react app” default setup will should have accurate stack traces out of the box.

To your point about best practices React, at least at the beginning was not supposed to be the entire stack, by design you needed other libraries to deal with large portions of the web state and as such it could only control a small part of your stack.

That being said with hooks and providers, it is gaining enough internal tooling to be almost “the whole stack” but still the philosophy remains.

Re: Algebraic Effects for React Developers

#19

I started learning React for starting a large project a few months ago. I have not really liked the experience very much. One seems to still need to know all the JS/CSS/HTML I've been using for 10+ years but also a new stack on top of it, simultaneously. Hooks are one of the strangest features I've seen in a language yet. I doubt they will be a lasting paradigm outside of the React ecosystem. I like JSX a lot. The id…

I too can't shake the feeling that hooks are off. I like JSX and the component model.

In React and like-minded projects, I look at a stack trace and see that it starts at some kind of batch renderer. I can't tell "why", "how" or sometimes even "what" broke. The input part of it is completely lost.

I work on a Backbone application where stack traces are much more obvious. They usually tell you the whole story. I find that juniors who were mostly exposed to React have a tendency to completely ignore stack traces, and am now wondering if they are just conditioned to them being unhelpful.

Re: Algebraic Effects for React Developers

#20

I started learning React for starting a large project a few months ago. I have not really liked the experience very much. One seems to still need to know all the JS/CSS/HTML I've been using for 10+ years but also a new stack on top of it, simultaneously. Hooks are one of the strangest features I've seen in a language yet. I doubt they will be a lasting paradigm outside of the React ecosystem. I like JSX a lot. The id…

Best way to debug react is to do it via your IDE debug functionality, to enable debugger on caught errors (if you get errors in other code you usually can blackbox it) or to utilize `debugger;` command. Don't forget browser extension for cases where no error happens.
Post reply on HN