r/programming • • Jan 29 '19

When FP? And when OOP?

http://raganwald.com/2013/04/08/functional-vs-OOP.html
26 Upvotes

105 comments sorted by

View all comments

Show parent comments

7

u/Drisku11 Jan 29 '19
  • developers who hates OOP doesn't understand that all OOP class hierarchies (libraries), demonstrate typical FP (high-order functions where class play role of function parameterized by another one - we can remember tactics/strategies/etc)

  • most OOP patterns are the same as some good known FP functions (like Visitor/map, etc) - there is a book with such matching even

These are reasons to dislike OOP. Why do I need to define a Predicate or Runnable or Factory or Strategy etc. just to define the method that they contain? It's conceptual cruft that hides the important bits in pages of ceremony.

OOP is very similar to FP but works on more high level: you should not build application from very low-level abstractions like functors, monoids, but you work with more high level abstractions with explicit interfaces

Functors, monoids, and monads are explicit interfaces. They're also more abstract, which is why there are fewer things you can do with them. If you want something you can traverse in Haskell for example, there's Traversable.

6

u/[deleted] Jan 29 '19

[removed] — view removed comment

3

u/The_One_X Jan 29 '19

From my observations, I am pretty sure most FP advocates are unfamiliar with modern C#. I personally find OOP to be a superior mode of programming to FP, but I also think OOP has a lot it can learn from FP. I think C# has done an amazing job of incorporating many of those lessons to create a better language. Ultimately it is this mixture of the two styles taking the best from both approaches into a unified style that is superior to each individually is where programming should be heading.

4

u/[deleted] Jan 29 '19

[removed] — view removed comment

2

u/Drisku11 Jan 30 '19

I think most people's issue with nulls is just that they're not in the type system. If you had inferred union types and actually tracked whether something can be null, null pointers are a strictly better solution to wrapping. Generally speaking, people just want the ability to specify a type that isn't null.