by jtdev · 5y ago · 0 comments
FP makes this relationship of change to time explicit. Instead of having a "single object" that "changes state" when some event occurs, you have two objects - one before the event, one after. Systems that rely on mutable state conflate these two and then force you to deal with the consequences of that conflation.
Modeling those as two distinct, immutable states provides enormous benefits over modeling it as a single state that "mutates". Doing this eliminates a large class of serious bugs.
The reason for these benefits is that far from trying to "escape the reality that the known universe and everything that happens within it is stateful," functional programming uses a more rigorous model of state that better reflects the relationships between states over time.
If that were the case I'd just fix your comment instead of appending another comment after the fact. But that would make the arguments harder to reason about I think.
> including our code
Do you use git? Or does your team all just edit the same code on a shared server? (The OO solution here is to make state 'private'. It supposedly doesn't really matter than you're all editing the same documents at the same time, because they're behind getters and setters)
> why does the FP crowd make state even more difficult to reason about?
State is difficult to reason about so we maximise out stateless code.
> talking down OOP
I talk down OOP when I treat it as the diff between OOP and FP. That is, coding is 80+% the same whatever you use. It's the last 10-20% where the differences emerge: Lambdas are better than anonymous inner classes. Not having null is better than having null. Not needing to cast is better than casting. Composition is better than inheritance. Stateless is better than stateful. Value-equality is better than reference-equality. Generics + type erasure is clunky without higher-kinded types.
This just isn't true in the slightest sense. Honestly, where does this kind of anti-OOP trope come from?
Encapsulation
Encapsulation is an object-oriented programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.
It's arguably the core concept of OO, and I don't believe it keeps data 'safe from outside interference and misuse'.