3 ms·
"Pure" FP languages eliminate state. All programs contain an (implicit or explicit) model of the domain they are computing on. Many aspects of the world (domain
by miked 18y ago
"Pure" FP languages eliminate state. All programs contain an (implicit or explicit) model of the domain they are computing on. Many aspects of the world (domains) that we need to model are stateful. Our programs, in modeling those domains, often must be stateful. This is why it's hard for programs to be entirely functional.
On the other hand, state dramatically complicates reasoning about code, since outputs are no longer purely a function of inputs. Moreover, even with lexical scoping, it's not immediately clear what the state variables are a function of. As the scope of state variables increases, it becomes ever harder to determine what a state variable is a function of. This is why programs should be as functional as possible.
Solution: a language like Clojure or Common Lisp, which naturally encourages a functional approach while allowing side effects when neeeded. Clojure has some advantages over CL in this regard, since it has several clever mechanisms such as agents and software transactional memory to control side effects.
- krschultz 18y agoBeing largely stateless is the hardest thing for me to wrap my head around when I first started writing Lisp code but after a while it is liberating. I still think that data representation is what scares most people away. People are used to defining their data as objects and not many people program any other way today.
- weavejester 18y agoPure FP languages eliminate implicit state. You can still have state; it just has to be explicitly passed in as an argument.
- eru 18y agoOr handled as a Monad.