by rspoerri · 2y ago · 0 comments
Functional programming on the other hand is better the closer we are to the hardware. It can be more efficient, and in some areas other ways just don't make any sense.
Both are important, and knowing only one structure is definitely bad. But still talking about an object-oriented mania feels like somebody hasn't gotten over the conflicts of 30 years ago.
A problem is mutability. Consider: "Is-a list of triangles a list of shapes?".
Most inexperienced people, using their intuition, would answer "Yes!", and try to design a "ShapeList" base class of "TriangleList", "CircleList", "SquareList"... and then puzzle over where to put the method "void add(Shape s)".
So you end up picking a subset of OO in which you take away inheritance, or mutability ("state"). But take those away and you don't really have OO any more (IMO)...
Even Eiffel got this wrong, fwiw. (https://staffwww.dcs.shef.ac.uk/people/A.Simons/research/pap...)
The problem was that all the students who had just been introduced to programming via Haskell where completely lost when they took the next intermediate programming class, which used Java.
A couple of years later I was using bash and C on Ubuntu from a CD someone handed me on Stephen's Green. Still better, but no click. C++ and Python ditto. Friends tried to get me into Ruby or Visual Basic but like the other languages they all felt like they were deliberately perverse. Like they knew how thoughts were turned into CPU instructions but wanted you to take the long way around.
The eureka moment for me was reading Learn You a Haskell. I don't code much in Haskell day-to-day, but I think in Haskell constantly now. Strongly-typed functional thinking maps pretty well onto lots of things I use nowadays like Tensorflow. I knew some guys who took a course on Haskell in the final year of their CS undergrad and they found it inscrutable.
All that to say, I really don't like OOP-mania, though of course sometimes a problem is well-suited to an object oriented solution. Learning functional programming from Haskell really open-end my mind, I wonder how much time I might have saved by learning that first.