See for example this comment [0] from the hooks RFC discussion how they could have been made more functional.
[0]: https://github.com/reactjs/rfcs/pull/68#issuecomment-4331556...
See for example this comment [0] from the hooks RFC discussion how they could have been made more functional.
[0]: https://github.com/reactjs/rfcs/pull/68#issuecomment-4331556...
Like Wikipedia states, you’re conflating “functional programming” with “pure functional programming”.
Definition of functional (from Wikipedia page you linked to): In functional programming, functions are treated as first-class citizens, meaning that they can be bound to names (including local identifiers), passed as arguments, and returned from other functions, just as any other data type can.
In C language you can do all that. But C is not a functional programming language at all. Neither is Hooks functional. Even assembly language has "functions" but it is not a "functional language".
They're not functional first like F# or Scala.
A programming language can embrace multiple paradigms.
Well then so is assembly language.
I never said it was. I said that hooks are a way of abstracting functionality that can't be easily represented as pure functions.
> they make it difficult to reason about which functions are pure and which are impure.
Hooks have to have 'use' at the start of their name to be recognized by React. It should be instantly obvious which functions are pure and which aren't as long as you don't wrongly namespace your pure functions with 'use'.
I do disagree with it though.
> hooks are a way of abstracting functionality that can't be easily represented as pure functions.
Yes, this is true, but in what is (IMO) a much less semantically clear manner than classes or a monadic interface. If a HookMonad or something similar were passed into components as an optional argument, I’d have very few complaints about hooks.
> Hooks have to have 'use' at the start of their name to be recognized by React.
Is this architecturally true or just conventionally true? It seems like this would just be determined by what they name the functions, which needs to be enforced by convention, but I suppose JS is dynamic enough that they could actually require the names conform to some standard.
Either way, it doesn’t prevent people from importing them with other names, and even if it did, digging through a large function searching for “use” function calls seems much less obvious than the presence of an optional function parameter or the fact that a component is a class.