5 ms·
In the newer versions of React with Redux, the components are all pure functions and state is centralized and passed down into the components. IMO it's as close
by jongjong 17d ago
In the newer versions of React with Redux, the components are all pure functions and state is centralized and passed down into the components. IMO it's as close as a codebase can be to pure functional programming whilst still functioning.
- pyrale 17d ago> IMO it's as close as a codebase can be to pure functional programming whilst still functioning. You know, people have put functioning codebases using pure functional programming languages like Haskell, Elm, Purescript, etc. I really don't see what in your opinion is too close to FP to work.
- kodoman 17d agoNot a frontend developer and my frontend skills are lacking, but the argument I think that is being made is that a react component should generally be written with no side effects and rely on signal for state change and do reactive programming. While of course something like Elm is more so this model and actually is functional from the get go. In js/ts react you are writing a lot of code that aims to be side effect free. Most programs code bases of course need some way of doing side effects and not being 100% pure so many haskell projects would not be classed as 100% pure.
- hurril 17d agoThat is just not the case. I have worked, full time, as a functional programmer coming up to 15 years, in different langauges. Actual functional programming and not merely doing web programming with React. "[...] pure functional programming whilst still functioning." I mean, what is this? When I read what you are saying here, you are saying that an "advanced codebase", whatever that means, using functional programming leads to centralized state and distributed components. And you know this because the codebase you are thinking about has this software architecture. I have been in such codebases too, they tend to be frontend and maybe that is just the way you have to do it, maybe not. But this is not a property inherent to functional programming. Solving problems with a component or object concept as a central abstraction for "a thing" is the OOP way. I know this because this is how I spent the first half of my career. You think you need a _substantive_ onto which you perform verbs. Nothing wrong with this though, I am not picking a fight with OOP. I can offer what I refer to when I talk about FP so that we can at least have a real thing to disagree over :) 1. model the domain and interactions with it with strong types such that neither interactions nor state can represent values outside of the domain. 2. parse, don't validate 3. Use modules, stateless collections of declarations, to organize stateless functions. No this. No self. 4. No magic code. I.e.: no null checks, no magic number checks, no arbitrary logic in four places that together make up the fact that prices can have taxes. Abstract it and "store" these runtime decisions using typed values, use functions that accept these typed values to force use of the aforementioned types. 5. Control the side effects. This does not mean that you have to use Haskell or monads or anything like that. Just that managing it is a good thing. 6. #5 implies keeping track of state. I.e.: no, you may not just willy-nilly read it from the persistent store, cache or file.