by cryptica · 7y ago · 0 comments
It gives you rerefential transparency at the expense of real modularity.
Real modularity can only be achieved through proper separation of concerns. The best way to achieve that is by categorizing system state and system logic and allowing chunks of logic to be colocated with the relevant parts of the system state. This is what OOP excels at.
With functional programming, you cannot colocate module logic with module state so you often end up with a large monolithic state store on one side of the system and logic which is completely decoupled and sitting on the opposite side of the system... Then the challenge is to apply functions to various relevant parts of the state to transform it in a referentially transparent way.
The modularity problem then comes when you need to make a change to the schema/structure of the state; whenever you change the structure of the state, you need you need to search through your logic to identify all the parts of the logic which depend on that state and update them to work with the new structure. This is a massive problem and leads to what OOP developers call spaghetti code.
Also, you seem unaware of the real restrictions on modularity caused by eager evaluation.
If you need to store state inside of that file, then it means that you are using it to affect the behaviour of functions which are exposed to the outside... Also, this approach would be sub-par because you would be constrained to singleton modules.
What you described sounds like a Haskell programming anti-pattern. It sounds like a feature which was hacked on top to allow Haskell to emulate OOP languages without actually doing OOP.
Also, lazy evaluation is a separate topic. OOP languages also support lazy evaluation.
Can you work on adopting a less flame war-y tone?
Think of it this way:
An array append function which adds an element to the input array is not purely functional.
An array append function which returns a new array with the new element appended is purely functional.
The same function applied to the same input will always return the same value, and won't cause that to break for any other functions.
Of course, this makes things such as IO tricky and yo ideally want to minimize and isolate the places where this happens on a lower level.
Haskell solves this with monads, which we have seen is a big hurdle for many developers. I personally think Idris's effect system[0] is a lot easier to deal with, but would be curious to see other approaches.
[0]: http://docs.idris-lang.org/en/latest/effects/index.html
>> The same function applied to the same input will always return the same value, and won't cause that to break for any other functions.
I think this is the essence of why a lot of developers use functional programming but I think that in this case functional programming is not a solution to the real problem which is an architectural problem.
If the relationship between different components in your system is clear and hierarchichal, you should never need to keep the same data/array in two places. You can come up with simple abstractions so that you only ever have one source of truth for each kind of state. That means you can read it anywhere but only write to it in one place.
I think that functional programming cannot solve this root problem, you will just end up with different symptoms. For example, instead of mutating a single array in unexpected ways, in FP, if you have multiple sources of truth, you might end up with multiple conflicting copies of the same data. Same root problem and it's just as difficult to identify and debug as in OOP, just different symptom.
Object oriented programming is abstracting over race conditions.
What you described is distributed computing, which (you are right) is fashionable. However, each 'computer' in the 'distributed computing' should be purely functional, referentially transparent, etc. Since that make it easier to reason about it as an 'object'.
These ideas are just tools for organizing information systems, no need to get too caught up in a label war, even emacs and vim are converging :^)
Nothing prevents you from having state in an haskell application. You just have to be explicit about it.
Whether the language ergonomics are better or worse than a language that allows state without an explicit type is another question but your reasoning is questionable.
There's ample evidence that Functional Programming (esp. with immutable data) gives you a lot of aspects of a 'module' for free.
Any function programming language can describe and enforce module boundaries. Some mostly at run-time, but that is A-Ok in my book.
I also find it funny you mentioned "large monolithic state" when most enterprise apps try to hide that fact that all your data is in a database (the large monolithic state), by stashing it into objects through some magic ORM...
My favorite part of working in Haskell professionally is that my coworkers never use imprecise folk programming terms like this :)
Also everything you said just doesn't ring true given my professional experience :)