DEV Community

loading...

Discussion on: Functional Programming vs OOPS : Explain Like I'm Five

Collapse
drbearhands profile image
DrBearhands

FP vs OOP is a false dichotomy.

FP is about lacking side-effects, or as I like to think about it, having a complete type system (over both data and effects). It's a subset of declarative programming, which in turn is the opposite of imperative programming.

OO is a guideline usually applied in imperative languages that advocates constructing a solution in terms of 'objects' which have predefined ways in which they can be accessed.

Functional style is a guideline applied on both declarative and imperative languages that advocates passing functions around as arguments to other functions.

In theory you can combine OO and functional styles but it's rare, as limiting the interaction you can have with an object seems to go against the notion of passing arbitrary functions. But I've seen it done in Scala for big data analysis.

OO generally expects mutability of objects, which can be a side-effect and therefore appears to be incompatible with FP. This can be resolved by making all objects linear types (or uniqueness types), or simply by dropping mutability.