3 ms·
Actually, some authors define objects as functions with an internal state. In that sense, objects derive from functions. For instance, in OCaml, the function "
by yodsanklai 13y ago
Actually, some authors define objects as functions with an internal state. In that sense, objects derive from functions.
For instance, in OCaml, the function "counter" defined as:
"let counter = let x = ref 0 in fun _ -> x := !x + 1; !x ;;"
is an object with one method that increments and returns the value of a counter.
In my opinion, OOP is intrinsically more complicated that FP because you can't really avoid complex patterns even to do simple things.
An example that comes to mind is the "Visitor" pattern. To me, it requires more mental gymnastic than what is found in most functional programs. It amounts to mixing higher order and functions with state which is something you try to avoid in FP.
But I admit that I'm not well-versed in OOP. I've always found it complicated. Not Objects per se, but design of big programs using classes with complex relations, UML, design patterns and so on...
- seanmcdirmid 13y agoI haven't used the visitor pattern in OOP in over 10 years and I write lots of code. There are many other better solutions to the expression problem than visitors. I don't bother with design patterns much or UML at all. I do mix my style up with FP when appropriate, but OOP is my dominant organizing principle. OOP really is just about object thinking, just like FP really is about thinking in terms of functions. All the other baggage in either paradigm is quite optional.