It's rather you carry your state with you, from function to function. Sometimes, a class is nicer, and I am primarily a FP developer.
Why not both? If the methods of a class don't mutate the state in place you're still dealing with pure functions.
A class that doesn't mutate state? So it doesn't encapsulate its own data? Well what's the point of classes then? That's just procedural programming with extra steps
Instead of += which returns nothing you have + which returns a new instance. It's how things like jax work - jax even explicitly forbids in place assignment. Classes become mostly about keeping things organised and syntactic sugar.
The one thing my anarchist friend and I agree on.
Ah, your code does not run in the real world then?
No, no. The trick is that you can say that your code doesn't have any effects, as all effects are performed by the runtime. That's the Haskell IO trick: Your code doesn't run in the real word. But the runtime system does.
The trick if formally correct. You code is in fact pure (= referential transparent).
But interpreting the code (running it) isn't. Just that you don't do that, the runtime does.
The result is called "staged imperative programming" by some. 😂
Funny enough the trick can be applied even to languages like C. So one can say that C is a purely functional language, as all the code does is merely describing how a program looks like. Especially as there is the pre-processor involved! (But I would even argue that any compilation step qualifies as this kind of mental trick.)
http://conal.net/blog/posts/the-c-language-is-purely-functional
Something something when you touch the functional developer's PROstate
Are we now in the context of gonads?
Gonads are monads in golang
gj. You’ve made a Postgres middleware
What are you talking about? Functional programming has state still, otherwise you wouldn’t be able to hold a website state. It emphasizes not mutating the state, but things like Redux exist specifically for functional state management.
The point is to isolate the states and minimize their propagation. You want any statefulness to be confined into predictable, explicit boxes in a way that doesn't affect the purity and the soundness of the rest of the code
Yes, state should be hyperlocalized and inaccessible to any process that doesn't need it. Global state is maddening to me.
Yes, it is best to make state immutable in functional programming, but OPs meme is just wrong. Functional apps are still stateful, they just don’t mutate the state.
The state should be isolated and most of the work you will do is on pure functions without state. Yes, some state still exists, but you don't work with it constantly. It's not at all unreasonable for one to think to themselves "no more state" when doing FP because the main work is state free.
That, or OP wants controversy to get the post going.
How can you have a state when there is no mutable cell?
-laughs in Haskell
No but seriously, there is no hidden state since many "true" functional languages don't want you to reassign variables and therefore you can't just put the state in a hidden private member and forget about it.
Brings me to my current default style - functional oop. It's kinda the most natural style when you use machine learning libraries like torch. As long as a method doesn't mutate the state of the objects it's still a pure function, python even makes that explicit with the self parameter.