by jongjong · 3mo ago · 0 comments
Most complex codebases I've seen which were pure Functional Programming were spaghetti code; unmaintainable.
What I saw every single time was that the project was syncing a huge amount of state in a central place and then passing it through a large number of components and sub-components. The top level component basically had to have full awareness of everything going on inside the system in order to do its job and there were no separation of responsibilities because none of the components had sovereignty over the state they needed to do their job independently. It's just components micro-managing components all the way down.
React with Redux is probably the best FP implementation I've seen thus far but even it is kind of a mess. I have nightmares about Redux Saga. The Redux Saga logo is literally a stylized drawing of entangled spaghetti.
Had Redux + Saga been presented to people as part of React at the time it was introduced, React would probably not have become so popular. Because people would have understood that it creates too much unnecessary baggage which isn't worth it. React was used as a gateway drug to Redux which was itself a gateway drug for Saga! And what I observed in practice is that most React apps are glitchy AF; and those glitches are usually difficult to reproduce and fix, even if you know all the ins and outs of the framework!
What you are describing is OOP. Passing messages between identities over calling pure functions with values.
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.
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.
"[...] 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.
to me the best way to design large systems is sort of like an ecs. you don't separate components by state + behaviour, you separate systems and state.
There's a reason why 99% of video games are OOP. That level of complexity is just too much for FP.
the current trend are ecs's which are distinctly not classical oop
Isn't one of the tenants of FP that nothing is mutable anywhere?