Hacker News new | past | comments | ask | show | jobs | submit login

I assume you are talking about React. It started fairly OOP. Now it's... something else? It's not functional. IMHO hooks and effects are a crazy form of OOP. It's like some weird dynamic scope data definition.



I'm not exactly sure how hooks are related to OOP. Their design was inspired by 'Algebraic Effects' which are more functional in nature than OO.

This gives a good breakdown: https://overreacted.io/algebraic-effects-for-the-rest-of-us/


Ah, that does make more sense, and is a language feature I've often thought about. It's usually just a pattern and not a first class feature, but with many problems as a result (many of which React itself encounters).

Lots of use of context managers in Python are for accomplishing this. Smalltalk error handlers are like this (different than try/catch). Or Scheme's with-output-to-file... I got the sense that variables that start and end with stars in Common Lisp are used for this, but I was never clear if it was convention or an actual language feature.

I think I'd like it in React too if they just hadn't tried to be so clever.


Isn't this basically the same tradeoff as Contexts vs Prop-Drilling?

You could achieve the same effects by passing down callbacks.

I thought the reason why this is good for Errors, Themes and Loading (Suspense), is because they're so common, that you can always expect someone up in the hierarchy to consider it, and therefore sacrifice some type safety for less verbosity.

The article mentions that "usually the fact that a function can perform an effect would be encoded into its type signature", which is why I don't understand the need in this example.


Honest question, I’m very curious. Do you still classify React as closer to an OO paradigm than functional?

Agreed hooks are… something else.


Running a function and then looking for magical side effects to effectively get multiple return values from that function sure isn't functional. And it shows in how unintuitive it is to reason about hooks and the leakiness of the whole thing.

I think it looks functional because it's only easy to reason about if you write functional code.

I suppose it tries to solve some of the same problems as OO, like related state and private transitions. But it feels like React itself is the God Object.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: