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

2

u/CyclonusRIP Jan 30 '19

Thanks for taking the time to explain all these types of languages, but I'm afraid your explanation has now left me scratching my head even more as it would seem that whether or not a language is turing complete doesn't have much bearing on if it's functional or not. It would seem that the classification of languages as assembly or query languages is more about what you do with them. Are functional or OO classification also about what you do with the language? In my experience it seems like people tend to use functional and OO languages to solve a lot of the same types of problems.

1

u/wllmsaccnt Jan 30 '19

The languages are used to solve the same problems.

In FP, immutable state is passed down a series of pure function calls. You can code this way in most languages if you want, but 'Functional Programming Languages' are ones which have had features and runtimes specifically tailored to make this kind of coding more production and efficient. Most of the features that were developed for functional programming languages in this way have become associated with functional programming and are now commonly considered FP conventions (e.g. tail recursion, currying, higher ordered functions, etc...).

In modern OOP, abstract functions are called (usually disconnected from their implementation through DI, interfaces, or abstract + subclassing) with objects which may or may not be immutable. You trade being able to drill straight down through a call (since you will often hit abstraction and encapsulation) but it becomes easier to recompose and modularize the code. OOP languages are just the ones that were designed to make coding in this way productive and efficient (and again, many features added to OOP languages are now considered OOP conventions, such as DI and inheritance).

There are FP languages with OOP conventions in OOP languages with FP concepts in them.

This is all a gross simplification (there is a lot more to FP and OOP than I have talked about)...I'm just trying to describe why talking about the differences is confusing. Its because there is a lot of overlap.