3 ms·
> the core of the programming philosophy is only concerned with the part where we push bits around uselessly. It's the opposite, for FP, OOP, imperative, that
by jabradoodle 3y ago
> the core of the programming philosophy is only concerned with the part where we push bits around uselessly.
It's the opposite, for FP, OOP, imperative, that is the part of the program which is easiest.
FP is about managing the difficult parts, and so is OOP. They just have different approaches, and note, many mainstream languages are incorporating FP concepts quite readily now.
- c_crank 3y agoMainstream languages incorporating FP concepts don't do so with the intent of encouraging totally pure stateless programs. What they do allow is calling the occasional anonymous function or using Map() instead of ForEach() or for().
- jabradoodle 3y agoTotally pure stateless programs are not the norm in functional programming. E.g. the functional core imperative shell pattern. It's also not just a syntax difference, mainstream languages are embracing immutability more and more, often as a default. The point is that calling FP academic is a tired trope and even if it is far from the dominant paradigm, there is clearly practical lessons to be learned whatever paradigm you program in.
- c_crank 3y agoThe only time I hear about a mainstream language being immutable by default is from Rust people telling me that Rust is a mainstream language now. A Haskell program covered in piles of monads to abstract all state away still follows the functional core imperative shell pattern, because the runtime is the imperative shell. This doesn't make such a thing desirable for other languages. The practical lesson I learned from dabbling with functional programming in academia is that functional programming is often impractical and does not offer any of the purported benefits of better code.
- TuringTest 3y agoMonads are just one design pattern for handling state, and not the only way. It's no different than having an OOP using dependency injection everywhere - it's a design decision that you use only when it makes architectural sense. A shell is not more imperative than a processor - both are Turing machines, a completely functional mathematical object. Seeing them as imperative is a semantic interpretation of the people watching it, not an inherent property.
- c_crank 3y agoFunctional languages have either converged on either just allowing mutable values or relying on Monads as the ways of handling state. I'm not aware of a third solution.
- TuringTest 3y agoYou can just use the classic temporal logic approach, where state is passed explicitly as a parameter and the new state is returned. This is what state monads are doing anyway under a hidden syntax, and for simple cases it may be easier that building a full dedicated monad.
- jabradoodle 3y ago> The only time I hear about a mainstream language being immutable by default is from Rust people telling me that Rust is a mainstream language now. Most mainstream languages are old, they can't be immutable my default without breaking backwards compatibility. I'm talking about the design direction of languages that are already based on mutability. For example, Java added Records which are immutable, as well as overhauling the date/time api with an immutable version. > This doesn't make such a thing desirable for other languages. I've used this pattern in other languages, none of this is a silver bullet that makes software engineering easy; but I do find it makes some code much easier to test and reuse.
- TuringTest 3y agoFP is not stateless, is state-aware. You need to declare what functions handle state, just like in Java you need to declare which functions handle exceptions.
- c_crank 3y agoC# including LINQ or Javascript including Promises isn't done with the intent of having all functions handle state and pass around a state of the world parameter (trying to actually do this in Javascript will lead to a lot of boilerplate and ugly corner cases, as one would expect in the language).
- epgui 3y agoWell, that's partly because these languages were never designed to be functional in nature, and partly because the approach you propose is not how FP works. I'm not sure what else you'd expect?
- c_crank 3y agoIf someone tells me that languages are adopting a functional approach, I would expect to see the tools and methods evolve to allow functional code to be written. What I am seeing is languages adopting specific functional methods that can be used or discarded, rather than encouraging the adoption of the actual style.